Results 1 to 10 of 13
I want to create a shell script that will run nmap on my computer every minute or so. Then, I want it to take the results, and compare them to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-05-2005 #1Just Joined!
- Join Date
- Apr 2005
- Posts
- 33
NMAP Automated Script
I want to create a shell script that will run nmap on my computer every minute or so. Then, I want it to take the results, and compare them to the previous one. If they are different, I want it to pop-up a window showing open and ports. Also, every hour, I want it to pop-upa window anyway, showing me the open ports.
Is there a way to get this script to:
a. Begin running on startup (I have mdk 10)
b. Run in the background, and then open a terminal window, showing the nmap scan results.
Thanks!
- 08-05-2005 #2Linux Engineer
- Join Date
- Apr 2005
- Location
- Buenos Aires, Argentina
- Posts
- 908
...
What makes you think that someone will do an script that does all that and post it for you? I mean, you're not asking for something THAT simple.. I think you should go to read some bash scripting stuff and try to do it yourself.
Also, if you can code C as your nick tells me, you can probably do some bash scripting as well.
Good luck.serzsite.com.ar
"All the drugs in this world won\'t save you from yourself"
- 08-05-2005 #3Just Joined!
- Join Date
- Apr 2005
- Posts
- 33
I only switched to linux a few months ago. C i know, bash im still working. Thanks anyway ,though
- 08-05-2005 #4Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
I'd say it actually is THAT simple.
Originally Posted by serz
Personally, I would put the script in cron, and make it do something like this:
The problem is, of course, just how you want to display it. Here, I used zenity, but countless other solutions are, of course, possible.Code:#!/bin/sh if [ -e /tmp/nmap-out ]; then # Use the output file as mutex echo already running >&2 exit 1 fi nmap hostname >/tmp/nmap-out 2>&1 if [ -e ~/.nmap-old ] && diff ~/.nmap-old /tmp/nmap-out >/dev/null; then diff -u ~/.nmap-old /tmp/nmap-out >/tmp/nmap-diff zenity --info --title=nmap --text="$(cat /tmp/nmap-diff)" rm -f /tmp/nmap-diff fi mv -f /tmp/nmap-out ~/.nmap-old
As for displaying the entire nmap output every hour or so, I'd just make a second script for that and put it, too, into cron, just with another interval. Of course, that one would be even simpler:
As for putting stuff into cron, see the manpages for crontab(1) and crontab(5).Code:#!/bin/sh nmap hostname >/tmp/nmap2-out 2>&1 zenity --info --title=nmap --text="$(cat /tmp/nmap2-out)" rm -f /tmp/nmap2-out
- 08-05-2005 #5Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
Your first script does not seem to erase /tmp/nmap-out
This thread made me try out a little experiment earlier:
I used an at command 1 minute in the future where I put just kedit
Then I continued doing other things on a different window.
kedit was never opened ! Does zenity have something different
which will allow it to open a window ? I don't have zenity so I can't
experiment with it.
- 08-05-2005 #6Just Joined!
- Join Date
- Apr 2005
- Posts
- 33
My idea was to have it display what it would display if I were to open a terminal window, and type: (excluding the prompt)
In other words, show a terminal window with that command typed in, plus results.Code:[admin @localhost admin]$ nmap -sV 192.168.1.103
- 08-05-2005 #7Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Oops, typo. I had written "mv -f /tmp/nmap-diff ~/.nmap-old" where, in fact, I meant to write "mv -f /tmp/nmap-out ~/.nmap-old". I've edited the previous post to correct my mistake.
Originally Posted by Santa's little helper
I hadn't tested the script or anything. I meant it more like a sample for starters than a final solution.
Maybe at unsets the DISPLAY variable? In any case, it is very clear that cron will unset DISPLAY, so that also needs correcting in my previous sample. I won't correct it, though, since I cannot figure out what setting of DISPLAY you will want. Maybe it's an xauth problem? You may want to redirect stdout and stderr of kedit to a tempfile to diagnose the problem.
Originally Posted by Santa's little helper
- 08-05-2005 #8Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Well, if you so much want to have the command displayed, just "echo" it:
Originally Posted by I_am_the_C_coder_FEAR_ME
As for using a terminal window, that may not be a perfect solution, since it will close again as soon as the program running inside it has finished. Of course, you can fix that with a "read" command or similar to pause it. As I mentioned in my previous post, that script I gave as an example is meant as a sample for starters rather than a complete and final solution, so I leave that up to you.Code:echo '[admin @localhost admin]$ nmap -sV 192.168.1.103'
- 08-06-2005 #9Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
The error message is kedit: cannot connect to X server
Originally Posted by Dolda2000
I also tried a two lines script
but I got the same error.Code:at> setenv DISPLAY :0 at> kedit >& /tmp/err
- 08-06-2005 #10Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
I don't know much (if anything at all) about KDE and QT. Could it be that it prints "cannot connect to X server" for multiple condititions, such as no DISPLAY variable, or wrong X authentication data? You may want to check if your display manager sets an alternative XAUTHORITY location or anything like that.
Alternatively, try with xlogo or some other Xlib program instead of kedit. That just might give a more accurate error message.


Reply With Quote
