Skip to content

Instantly share code, notes, and snippets.

@paralax
Last active June 1, 2018 16:16
Show Gist options
  • Save paralax/d7bf2e95729eb7037a6b2950d294e3d3 to your computer and use it in GitHub Desktop.
Save paralax/d7bf2e95729eb7037a6b2950d294e3d3 to your computer and use it in GitHub Desktop.
TCP connect() scanner with banner grab
<?php
$ports = range(20, 100);
$IP = "192.168.1.50";
$results = array();
foreach ($ports as $port) {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>0, 'usec'=>100));
socket_set_option($sock, SOL_SOCKET, SO_SNDTIMEO, array('sec'=>0, 'usec'=>100));
if (@socket_connect($sock, $IP, $port)) {
socket_recv($sock, $buffer, 1024, 0);
$results[] = array($port, "OPEN", $buffer);
echo($port . " - " . $buffer . "\n");
} else {
$results[] = array($port, "CLOSED", "");
echo($port . " - " . "CLOSED" . "\n");
}
}
print_r($results);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment