Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
network ping sweep script???
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Wed Aug 07, 2002 8:06 pm    Post subject: network ping sweep script??? Reply with quote

Would it be possable for me to write a small script that could do a ping sweep of my subnets on my network throughout the day like one an hour for a week and dump the number of reponding hosts to a file that I could then import into excel (or OpenOffice's equivlent) and graph?

Right now, I can do a ping sweep with nmap by typeing

Code:
nmap -sP -Pl -n 10.5.0.0/16


And after a few min, it'll tell me how many hosts are up on my network that repond to pings. I just need something that will automaticly do this once an hour or so and dump the number of up hosts to a file.

Any ideas? I've never proramming anything in my life, so kinda go easy on me. :?

-ee99ee2
_________________
ServerMotion
Back to top
View user's profile Send private message
klieber
Administrator
Administrator


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Wed Aug 07, 2002 8:25 pm    Post subject: Reply with quote

OK, two helpful tips that should show you the way. First, how to direct the output of nmap to a file:

Code:
nmap -sP -Pl -n 10.5.0.0/16 > /path/to/myfile.txt


Use ">>" instead of ">" if you want to append the data onto the end of an existing file.

Second tip: cron is your friend. :) It can schedule things for you under a variety of time-based criteria, including once per hour. There's thousands of web resources on cron, as well as your Friendly Man Pages, so start there.

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Sun Aug 11, 2002 10:27 am    Post subject: Reply with quote

Okay that'll work, but the problem is I only need what's at the end of the results. nmap will display every host that's up.... I only need the number of hosts that's listed about 2 lines from the very bottom in the end. How can I only filter this information?

-ee99ee2
_________________
ServerMotion
Back to top
View user's profile Send private message
rac
Bodhisattva
Bodhisattva


Joined: 30 May 2002
Posts: 6553
Location: Japanifornia

PostPosted: Sun Aug 11, 2002 10:43 am    Post subject: Reply with quote

Code:
nmap -sP -PI -n 10.5.0.0/16 | perl -ne 'print "$1\n" if /(\d+) hosts up/'

_________________
For every higher wall, there is a taller ladder
Back to top
View user's profile Send private message
klieber
Administrator
Administrator


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Sun Aug 11, 2002 11:35 am    Post subject: Reply with quote

Or, if you don't want to use perl, the following would work:

Code:
nmap -sP -PI -n 10.5.0.0/16 | grep "[0-9]* hosts up"


Or, you could use tail:

Code:
nmap -sP -Pl -n 10.5.0.0/16 | tail -1


Or theres about 43,000 other different ways you could do it as well. (sed, awk, etc.) :)

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Mon Aug 12, 2002 1:02 am    Post subject: Reply with quote

Dang... u all are good... I tried the perl thing, and I just added a >> <file name> at the end of it.... that'll work great!!!

Thanks guys!!!! woohoo!

-ee99ee2
_________________
ServerMotion
Back to top
View user's profile Send private message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Mon Aug 12, 2002 1:10 am    Post subject: Reply with quote

Hey I just had an idea. Would there be a way to also put date and time in that file to where when I import it into excel or whatever the results are in column 1, time in column 2, and the date in column 3? Just wondering....

Thanks!

-ee99ee2
_________________
ServerMotion
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Mon Aug 12, 2002 4:49 pm    Post subject: Reply with quote

This is *nix. Of course you can. ;)

Oh, you want to know how. Try this: (again, one of many)
Code:
echo `nmap -sP -PI -n 10.5.0.0/16 | perl -ne 'print "$1\n" if /(\d+) hosts? up/'`,`date +%H:%M,%Y.%m.%d`


This produces a comma-separated file that Excel can open without modification. Included is also a bugfix that lets the script function properly when there is only one host up (the ? after hosts).

You can just stick that in your crontab to run it automatically. (man crontab) If you don't like the date/time format, man date and change it. ;)

Oh, and since you want to keep records of this, use the >> operator to append to the existing file rather than replacing it.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Mon Aug 12, 2002 10:49 pm    Post subject: Reply with quote

hehe.... a bug fix.... hahah.... thanks!!! :-D

-ee99ee2
_________________
ServerMotion
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum