A serial flasher who admitted exposing his private parts to a four-year-old girl has been given a six month jail sentence.