| View previous topic :: View next topic |
| Author |
Message |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Tue Feb 27, 2007 10:08 am Post subject: filter out ports + state |
|
|
Im using nmap to do portscan's.
I use:
| Code: | | set result "[exec nmap -sT -P0 -p <port1,port2,port3,etc> <host/ip>]" |
The return result from nmap is:
| Quote: | Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2007-02-27 08:53 EST
Interesting ports on <resolved.hostname> (0.0.0.0):
PORT STATE SERVICE
1080/tcp closed socks
8080/tcp closed http-proxy
????/??? open/closed ????
Nmap finished: 1 IP address (1 host up) scanned in 0.018 seconds
|
I need to filter out the:
resolved.hostname (0.0.0.0)
and the port, state, and service name for each port
How can i do this, a simple regexp or a few lrange's or something?
Thanks in advance! _________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Tue Feb 27, 2007 11:54 am Post subject: |
|
|
| Code: | | regexp -line {^Interesting ports on <([^>]+)> \(([^)]+)\)} $result x name ip |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Wed Feb 28, 2007 7:06 am Post subject: |
|
|
Thanks user, that filters out the <resolved.hostmask> (0.0.0.0) bit, but how can i get the port state and service into a list.
I tried a regexp,
It works, but it just returns the first match, i need to filter out all the ports into a list like:
set portlist {
"xxxx/tcp open/closed/filtered ????"
"iiii/tcl open/closed/filtered oooo"
}
So then i can use a foreach loop on portlist
Thanks in advance! _________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed Feb 28, 2007 9:16 am Post subject: |
|
|
Using regexp:
| Code: |
foreach line [split $result \n] {
if {[regexp {(\d/.*?\n)} $result match port]} {
lappend ports $port
}
}
|
Someone else can prolly give a better regex but that should grab the data you want. Then you'll have all of the data in the $ports var. |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Wed Feb 28, 2007 11:55 am Post subject: |
|
|
Thanks guys It works now   _________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
|