The present invention provides a fly repellent which comprises a by-product of breeding black soldier flies; the by-product comprises one or more of a pupal case of a black soldier fly, a corpse of an adult black soldier fly, and excrement of a black soldier fly. The fly repellent targets one or more types of flies including houseflies, anthomyiidae, blow flies, or flesh flies. In the present invention, a number of by-products produced during the breeding of black soldier flies are used to repel flies. The active ingredient in these by-products is fly-repelling pheromones, which could significantly decrease the lingering, foraging or ovipositioning of flies on livestock excrement, feeds or foods. The fly repellent made from the by-product of breeding black soldier flies or methods developed by using the by-product could be used in a farm environment, an animal body, a human living environment or a food processing factory.