ok so this is my first ever attempt at php, and what i wanted to do was create a script that would load a file of ips and ports, put them into an array and connect to each pair and get the http header info. Unfortunately I can't get it to work, and some of the errors I receive make absolutely no sense at all.
Here are the errors:
Notice: Undefined variable: i in c:\program files\apache group\apache\htdocs\listinfo.php on line 14
Notice: Undefined variable: i in c:\program files\apache group\apache\htdocs\listinfo.php on line 18
Notice: Undefined index: in c:\program files\apache group\apache\htdocs\listinfo.php on line 18
Fatal error: Call to undefined function: socket_create() in c:\program files\apache group\apache\htdocs\listinfo.php on line 22
The php_socket.dll is enabled in php.ini so i don't know what that problem is. Below I have included the code for you to peruse 🙂
<?php
error_reporting (E_ALL);
$filename = "c:/program files/apache group/apache/htdocs/ip.txt";
$fp = fopen($filename, "r");
$ip_port = fread($fp, filesize($filename));
//info is in one long string with carriage return separating
fclose($fp);
//separate ip/port pairs into arrays
//now $line[0] has a ip-port pair, etc
//need to separate ip and port of each pair now
$line = explode("\n", $ip_port);
while ($i <= sizeof($line))
{
//explode to get ip/port
$info_pair = explode (":", $line [$i]);
//create a socket to connect to the ip address and port
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) { echo "Couldn't create the socket mang :(\nReason: " . socket_strerror ($socket) . "\n";}
else { echo "Socket creation is money :)\n";}
echo "Attempting to connect to '$line[0]' on port '$line[1]'...";
$result = socket_connect ($socket, $line[0], $line[1]);
if ($result < 0) {echo "Couldn't connect mang :(\nReason: ($result)" . socket_strerror($result) . "\n";}
else {echo "Socket connection all good in da hood :)\n";}
//all right, we should be connected; now to see what kind of info we can gather.
$in = "HEAD / HTTP/1.0\r\n\r\n";
$out = '';
echo "Sending HTTP HEAD request mang...";
socket_write ($socket, $in, strlen ($in));
echo "Word.\n";
echo "Reading the response:\n\n";
while ($out = socket_read ($socket, 2048)) {echo $out;}
echo "Closing socket...";
socket_close ($socket);
echo "Ok it be closed.\n\n";
$i++;
}
echo "IP/Port Pair List is Complete.\n";
echo "Program written by miteymous 2002.";
?>