IT / Linux / Script...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] IT / Linux / Scripting Question

12 Posts
8 Users
0 Reactions
80 Views
Posts: 773
Free Member
Topic starter
 

I want to achieve the following:

1)Scan a range of IP addresses
2)For any IP address that has port 80 open, record some useful information about the website such as the first 50 characters on the first page and certain meta data.
3) log the result so that a specific web site can be found.

I'm quite happy working with Linux and nmap at a command line but need some suggestions about looping through multiple web sites recording the mentioned information.

Thanks.


 
Posted : 30/06/2014 11:54 am
Posts: 773
Free Member
Topic starter
 

Looks like Lynx combined with some grep will work.


 
Posted : 30/06/2014 12:13 pm
Posts: 0
Free Member
 

i can't think of an easy way to do that, or any reason why you would want to. But just beware that should the host's be using vhosts then you might just get the default apache/iis/lighthttpd..... page when doing a GET to port 80 of the ip.


 
Posted : 30/06/2014 12:38 pm
Posts: 0
Free Member
 

ping IP, if responsive, telnet to port 80, use curl or wget to pull the content?


 
Posted : 30/06/2014 12:49 pm
Posts: 8177
Free Member
 

What about a simple for-each loop?

for each x in n ; do < what ever your'e doing to extract the data>


 
Posted : 30/06/2014 12:58 pm
Posts: 8819
Full Member
 

Internal IP addresses or external/Internet ones?

Python has some libraries that you could use for that, but the only script I have that comes close is one that parses nmap XML output from a ping sweep.


 
Posted : 30/06/2014 1:03 pm
Posts: 0
Free Member
 

that's pretty simple to do.

How are you generating the list of IP addresses? Are they sequential, a list in a file or on the command line?


 
Posted : 30/06/2014 1:32 pm
Posts: 0
Free Member
 

the function would be something like:

function getheader {

if [ $# != 1 ]; then
return 1
fi

host $1 &>/dev/null
if [ $? != 0 ]; then
return 1
fi

nmap -p 80 $1 2>&1 | grep "80/tcp open" &>/dev/null
if [ $? = 0 ]; then
curl -q $1 2>/dev/null | tr -d '\n' | cut -c 1-50 > $1.txt
else
return 1
fi

return 0

}

then just write a loop calling getheader <ip>

That should work; it could be cleaner as that will spawn a lot of processes so you could do the tr | cut bit in awk; however that would take longer than 2 mins 🙂 As I would need to read the man page

or do you need help with the loop part?


 
Posted : 30/06/2014 1:45 pm
 pdw
Posts: 2206
Free Member
 

I wouldn't bother using nmap. Just let curl try, and use a short --connect-timeout to fail quickly in case the target is dropping rather than refusing connections.

for ip in 'cat ips.txt' ; do echo $ip ; curl http://$ip/ --connect-timeout 3 | head -c 50 ; echo ;done > log.txt

EDIT you need backticks around "cat ips.txt" but the forum software can't cope with that...

purpleyeti makes a good point - connecting via a URL with an IP in it may not get you the expected result due to virtual hosting.


 
Posted : 30/06/2014 2:09 pm
Posts: 0
Free Member
 

curl FTW


 
Posted : 30/06/2014 2:14 pm
Posts: 0
Free Member
 

If you are going to use:

for ip in 'cat ips.txt'

You may want to first set IFS=$'\n'


 
Posted : 30/06/2014 2:16 pm
 pdw
Posts: 2206
Free Member
 

You may want to first set IFS=$'\n'

Why? Default for IFS already contains newline.


 
Posted : 30/06/2014 2:35 pm
Posts: 0
Free Member
 

by settin gthe IFS you ensure that lines in a file are kept intact when using $(cat $file); not that important in this case but still a useful thing to set to ensure that each line = one variable.


 
Posted : 30/06/2014 4:11 pm

6 DAYS LEFT
We are currently at 95% of our target!