Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ip = '8.8.8.8';
- $port = '53';
- $timeout = 10; // seconds
- $socket = socket_create(AF_INET, SOCK_RAW, getprotobyname('udp'));
- if(!$socket) {
- die('Aborting');
- }
- require_once 'Hexdump.php';
- $packet = pack (
- 'nnnn', 0, $port, 8, 0
- );
- hexdump($packet);
- socket_sendto($socket, $packet, strlen($packet), 0, $ip, $port);
- while(TRUE){
- $read = array($socket);
- $write = NULL;
- $except = NULL;
- $select = socket_select($read, $write, $except, $timeout);
- if ($select === FALSE)
- {
- die(socket_strerror(socket_last_error($socket)));
- }
- if ($select === 0)
- {
- // timed out
- continue;
- }
- // we cannot receive the ICMP response in PHP, as the
- // PHP engine will handle this "for us" :|
- $ret = @socket_recvfrom($socket, $recv, 65535, 0, $host, $port);
- if(!$ret) {
- die(socket_strerror(socket_last_error($socket)));
- }
- echo "\n";
- hexdump($recv);
- // we got a response, the port is open
- die('port open');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement