From: angels Blog Source URL:Http://www.sablog.net/blog/archives/479/
The program I saw on the blog of small A (angel) was very simple and powerful! Haha !~ PHP is used for implementation. I added code comments on the basis of his writing, so that it is easy for friends who do not understand PHP to understand. I don't need to talk about anything nonsense and go to the code!
// Execute the following PHP script to guess if port 3306 is enabled on the specified database server.
Code-1:
<? Php
$ Hostdb = array (
192.168.168.10,
192.168.168.20,
192.168.168.20,
192.168.168.40,
192.168.168.50,
192.168.168.60,
192.168.168.70,
192.168.168.80,
192.168.168.90,
192.168.168.100
); // Place these IP addresses in a predefined array.
$ Dbu = root; // This is the pre-defined database username
$ Dbp = 1qaz2wsx; // This is the password of the pre-defined database.
Foreach ($ hostdb as $ host) {// use foreach to traverse the pre-defined array
If (@ mysql_connect ($ host, $ dbu, $ dbp )){
Echo $ host.-. $ dbu.-. $ dbp... OK <br>; // print it out if it meets the pre-defined user name and password.
}
}
Echo done .;
?>
// The following code scans the specified IP address segment.
Code-2:
<? Php
$ Ips = 192.168.168.; // the pre-defined CIDR block is CIDR Block C.
$ Dbu = root; // pre-defined user name
$ Dbp = 1qaz2wsx; // pre-defined Password
For ($ I = 1; $ I <254; $ I ++) {// set the for loop, accumulate one by one on the basis of 192.168.1.1 until 192.168.1.254
If (@ mysql_connect ($ ips. $ I, $ dbu, $ dbp) {// try to connect to it
Echo $ ips. $ I.-. $ dbu.-. $ dbp... OK <br>; // print it if the connection is successful.
}
}
Echo done .;
?>