Someone is Attacking my server i want to create auto ip blocker. Like i put the code in the program and create and run when attacker attack ip get banned in my firewall through that Software.
The IP is not enough to detect/prevent DDOS attacks, I would also not recommend using PHP to do that job for you. You can use many DDOS protection software like APF, BFD, DDoS and RootKit Utilities or online services like mentioned by Sarah (CloudFlare).
You wont be able to stop the ddos with php scripts. Cloudflare (free version) will safe you some bandwidth but there is no real protection. I suggest you to go with a ddos protected hosting provider.
your hacker wont be using their ip address they will either be using a free wifi connection or a wifi connection they have hacked into. They will also have changed their mac address and most likely be running from a live disc which means they can run it on virtually any computer out there. If they are good enough they will hack you know matter what you do. Best option would be to look for vulnerability's in your scripts on the server.
HOW are they attacking? Via HTTP requests? Some other vector like probing FTP or SSH? What software are you running that is being attacked? You really didn't say enough of anything for there to be an actual answer... what's the site? What's the software? What type of "attack"?
First of all, you should limit the number of simultaneous connections from single IP or subnet in your firewall, to make queries do not reach the web server