Snoop perl script


 
Thread Tools Search this Thread
Operating Systems Solaris Snoop perl script
# 1  
Old 11-20-2009
Snoop perl script

Hi ,

I would like to write a perl script with the snoop command to capture packets from a specific IP address to a node (incoming packets) and packets from that node for the same session to another node and save the capture to a file. I would like my script to be able to read my IP all the time from the keyboard. I would like also to be able to determine for how how long the script should run. Let's say 60 seconds and then kill the snoop process after that period. Below is an example of the command.

snoop -o /tmp/snooper -V 128.50.1.250

let's say my snoop is called snoop1. I would like to be able to execute that way: ./snoop1 128.50.1.250 60.......where the 128.50.1.250 is the ip I want to capture the packets from and 60 the amount of time I want the script to run and then kill the snoop process.

Thanks for your help.
# 2  
Old 11-21-2009
Why do you want to do that in perl when a simple shell script would do it ?
# 3  
Old 11-24-2009
I wanted to do it in perl, because I am learning perl. I don't shell scripting. But, if you can send me the shell scripting you have that can do it that will help. At least, I can do it and use it as a guideline if I want find a way to do in perl. Thx so much. I would appreciate it.
# 4  
Old 11-26-2009
I haven't been able to find a way to do it for a specific amount of time yet,
but you could just add the -c option, you will probably get approximately 1000 packets per minute or so. If you think it might be more, increase the count.

Code:
snoop -o /tmp/snooper -V -c 1000


I'm not the best shell scripter, so this might be a little dirty, but here is how I would do it with bash shell:

Code:
#!/bin/bash

STRING=$1

snooper() {
   snoop -o /tmp/snooper -V -c 1000 $STRING
}


readstring() {
        echo -n "What would you like to snoop today? "
        read STRING
        snooper
}

if [ $1 > 0 ]
 then
    snooper
 else
    readstring
fi

# 5  
Old 11-26-2009
Here is something both simpler and complying with the requirements:
Code:
#!/bin/ksh
snoop -o /tmp/snooper -V $1 & sleep ${2:-60} && kill $!

# 6  
Old 11-27-2009
Thanks all,

jlliagre's idea was great! I tried it. It didn't work at first . It gave me an error stating wrong time period for sleep.

I modified it and tried it that way....

#!/bin/ksh
snoop -o /tmp/snooper -V $1 & sleep $2 && kill $!

I can enter the ip and the time period for sleep and then kill the process after the time period. But, I am wondering how sure I can be that this kill $! will only kill the snoop process that I am running and not any other process that is running.

I am wondering if it will be safer to to have script return the process ID for the snoop that I am running and then kill that process only.


Please let me know. Thanks so much,
# 7  
Old 11-27-2009
Quote:
Originally Posted by Pouchie1
jlliagre's idea was great! I tried it. It didn't work at first . It gave me an error stating wrong time period for sleep.
That's weird. That syntax simply set a default value (60 seconds) if no second parameter is supplied.
Quote:
But, I am wondering how sure I can be that this kill $! will only kill the snoop process that I am running and not any other process that is running.
It can't by design. $! is the pid of the last background process.
Quote:
I am wondering if it will be safer to to have script return the process ID for the snoop that I am running and then kill that process only.
That would have no advantage.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Solaris

Live snoop analysis

Dears, I am trying to run a bash script to take a snoop on an interface with a certain port for like 5 minute and once the snoop is finished I need to parse the snoop file on unix/solaris without using WIRESHARK or ETHERAL. the snoop that I will capture will be for DIAMETER Protocol and... (4 Replies)
Discussion started by: jojo123
4 Replies

3. Shell Programming and Scripting

snoop script in background

Hi I want to write a script for snoop which can do snoop for 30 min and then process should be killed automatically I am using below codes #!/usr/bin/ksh snoop -d igb0 -o /opt/temp/abc.pcap sleep 1500 kill -9 `ps -ef|grep -i snoop |grep -v grep|awk '{print $2}'` But process is not... (3 Replies)
Discussion started by: anish19
3 Replies

4. Shell Programming and Scripting

Script to capture snoop output

Hi Everyone :), Need your advice as I'm new to UNIX scripting.. I'm trying to write a script to capture snoop output for 5 minutes for every hour for 24 hours. To stop snoop, I need to press Control-C to break it. This is what I got so far, but now I'm stuck! :confused: The script: # cat... (2 Replies)
Discussion started by: faraaris
2 Replies

5. UNIX for Advanced & Expert Users

FTP Snoop

Hi, Can anyone please tell me a ftp site where I can download the solaris snoop package? I need to download the package so I can use the command in a Linux environment instead of using tcpdump. Need practice with snoop. Thanks for your help. (3 Replies)
Discussion started by: Pouchie1
3 Replies

6. Shell Programming and Scripting

Need help howto make a script for Set SNOOP run for 5 minutes

Hi all, I want to monitoring my interface every 6 hours where i want to run snoop command to capture all packet through the interface, so i want running snoop then snoop will run for 5 minutes after that snoop stop then will start again after 6 hours than run for 5 minutes again. thereis any... (9 Replies)
Discussion started by: tindasz
9 Replies

7. Shell Programming and Scripting

Snoop Script

Hi, I want to write a script that checks an interface with the snoop command, if there is no traffic in 10 minutes on port 123 from the ip add 10.*.*.* it should send a e-mail.but i don't know how to start writing this script does anybody have an idea or an sample script that i can modifi. ... (2 Replies)
Discussion started by: tafil
2 Replies

8. Solaris

snoop command

Hi. I'm trying to capture traffic with the snoop command using the net expression but I fail when a I've to specify a subnet ex: 10.201.64/18 Did you know the correct syntax? I've tried with snoop -ta -x0 net 10.201.64.0 255.255.192.0 but doesn't match. Thnx (4 Replies)
Discussion started by: kurtolo
4 Replies

9. Solaris

Snoop Functions

Hello! It is my first post in this forum :). I`m facing a strange issue. I am using a Solaris 8 as OS, and using the ipnat (ipf) to NAT an incoming port to another, as following: Host SUN with Solaris 8/NAT WEB Page (A.B.C.D:80) ---> |A.B.C.D:80 ->... (0 Replies)
Discussion started by: mf_lattanzi
0 Replies

10. UNIX for Dummies Questions & Answers

snoop equivalent

is there a snoop equivalent in other flavors of unix? HPUX, SCO or linux. TIA Peter (2 Replies)
Discussion started by: pbonilla
2 Replies
Login or Register to Ask a Question