Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created February 3, 2011 00:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save emad-elsaid/808796 to your computer and use it in GitHub Desktop.
Save emad-elsaid/808796 to your computer and use it in GitHub Desktop.
IP scanner, give it range of IPs and it'll return the website title
<?php
/*
* @Script: IP Scanner
* @Version: 0.1
* @Author: Emad Elsaid
* @Email: blazeeboy@gmail.com
* @Website: http://blazeeboy.blogspot.com
* @What is that ?:
* that is a ip acanner script
* you can give it a range of IP addresses and it'll
* get the website title of that page or notify that
* this is not a website at all
* i developed it becase when we made a 2011 revolution in Egypt
* i cannot access any nameserver but i can access one website
* then i made a nslookup command to get the ip of that website and then
* created that script to get the available website for me.
* i really don't know how to get the facebook.com ip address using that script
*
* @How to use ?
* you need to modify the $range variable
* every octet could be written as 1 number like : 1, 3, 5
* or you can specify a whole range to enumerate between : 1-255, 24-26
* then fire it from terminal not browser, to get a continual output.
*/
$range = '69.63.189.2-255';
$range = explode('.', $range );
foreach( $range as $index=>$octet )
$range[$index] = array_map( 'intval', explode('-',$octet) );
// 4 for loops to generate the ip address 4 octets
for( $octet1=$range[0][0]; $octet1<=(($range[0][1])? $range[0][1]:$range[0][0]); $octet1++ )
for( $octet2=$range[1][0]; $octet2<=(($range[1][1])? $range[1][1]:$range[1][0]); $octet2++ )
for( $octet3=$range[2][0]; $octet3<=(($range[2][1])? $range[2][1]:$range[2][0]); $octet3++ )
for( $octet4=$range[3][0]; $octet4<=(($range[3][1])? $range[3][1]:$range[3][0]); $octet4++ )
{
// assemble the IP address
$ip = $octet1.".".$octet2.".".$octet3.".".$octet4;
// initialise the URL
$x = curl_init( $ip );
// output buffer start becase it damn output the page HTML
ob_start();
// get page HTML
curl_exec( $x );
// get HTML from output buffer
$buffer = ob_get_contents();
// clean buffer
ob_end_clean();
// get the title position
$title_start = strpos( $buffer, '<title>')+strlen('<title>');
$title_end = strpos( $buffer, '</title>');
// print the result for that IP address
echo $ip." : ";
if( $title_end!==false ) // if title tag exists
echo trim(substr( $buffer, $title_start, $title_end-$title_start ))."\n"; // print title
else if( strlen($buffer)>0 ) // if there is a response
echo "Cannot get title\n";
else
echo "[Not a site]\n"; // if the isn't any response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment