I have an iPhone 3G 16GB with iOS 4.0.2 and my wifi is not working, I tried to fix it with reset network settings and other quick fixes like that but it still doesn't work. Sometimes it sees wifi networks but I can't connect. I don't think is a hardware problem because I can see the wifi MAC address on the device.
Version: 4.0.2 (8A400) (jailbreak with redsnow)
Modem Firmware: 05.13.04
PS: On 3.1.2 the same thing. (jailbreak with blackrain)
Downgraded at 3.1.2, again…still nothing (jailbreak with redsnow)
Best Answer
It may still be a hardware issue -- I had a similar problem last year. But since you say that your phone sometimes does see a wifi network, there's hope that the hardware is okay.
First, follow the comments posted here to make sure you're running a completely normal OS without any hacks or modifications.
Then, here's Apple's description of how to reset the network settings.
Lastly, if it still won't work, check my link above.