LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-04-2007, 08:48 PM   #1
tybalt
LQ Newbie
 
Registered: Jan 2007
Posts: 6

Rep: Reputation: 0
A little help with redirecting output


Can someone help explain to me how I can pull certain information out of a file and direct it towards a newer one. I've seen the commands: "sed, grep, awk and cat" and know it has something to do with them. But I just can't seem to find the answers that I'm looking for. What I'm wanting to do is take the output from a nmap scan and only foward the IP listed in there that have open specified ports to another file. This way the list of IP can be used for other programs. He's an example of what Im looking for:

Code:
Starting Nmap 4.20 ( http://insecure.org ) at 2007-08-04 20:45 CDT
Interesting ports on neptune (192.168.100.10):
Not shown: 1694 filtered ports
PORT    STATE SERVICE
21/tcp  open  ftp
139/tcp open  netbios-ssn
445/tcp open  microsoft-ds

Nmap finished: 1 IP address (1 host up) scanned in 32.021 seconds
Then filter out those results via a script or something to only list the IP of hosts that have port 21 open

Code:
192.168.100.10
 
Old 08-04-2007, 10:08 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Could you post a sample input that has more than one target found?

Code:
#n
/Interesting/,/^$/{
 /Interesting/{
               s/.*(\(.*\)):/\1/
               h
              }
 /^21\/tcp/{
               g
               p
          }
                  }
Code:
sed -f nmap.sed nmapsamp
192.168.100.10
Inside a range between "Interesting" and a blank line, if it is the "Interesting"... line, the line is replaced with the IP address and saved in the Hold register. If a line starts with "21/tcp", the Hold register is retrieved and printed.

Last edited by jschiwal; 08-04-2007 at 10:13 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting output using > cmk77 Slackware 8 11-10-2006 02:08 AM
Redirecting sh output to a pipe elmafiacs Programming 0 05-10-2006 01:55 PM
Redirecting output into a filename pbickerd Linux - Software 10 02-24-2006 02:41 PM
Redirecting mplayer output driptray Linux - Software 1 10-12-2004 07:42 AM
redirecting xmms output durden2.0 Linux - Software 0 03-06-2004 07:29 PM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration