LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-11-2011, 02:58 PM   #1
t.othoneos
LQ Newbie
 
Registered: Oct 2011
Location: Athens, Greece
Posts: 16

Rep: Reputation: Disabled
Whois a command output


Hey everyone,

I have a file that has IP addresses and usernames like so:

1.2.3.4 usera@net.com
5.6.7.8 userb@other.com
7.5.6.3 user2@some.com

there are about 26000 lines.

What i need to do is use the whois server whois.cymru.com and get the ASNumber and Country code for each IP address, and then have a result like this

1.2.3.4 usera@net.com 6799 GR
5.6.7.8 userb@other.com 2056 EU
7.5.6.3 user2@some.com 32557 UK

A normal whois on that server would be like:
whois -h whois.cymru.com " -c -o -f 75.126.162.205"
and the result : 36351 | 75.126.162.205 | US

The server itself provides bulk queries with netcat but for some reason, the results are more than the IPs provided.

I can extract the IP addresses with a "cut -f 1 file". Then I'm stuck.
PLS HELP
 
Old 10-11-2011, 03:33 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What about something like this?
Code:
while read ip mail
do
  var="$(whois -h whois.cymru.com " -c -o -f 75.126.162.205" | tail -1)"
  asn=$(echo $var | awk '{print $1}')
  cod=$(echo $var | awk '{print $NF}')
  printf "%15s %s %d %s\n" $ip $mail $asn $cod
done < file
 
Old 10-11-2011, 03:44 PM   #3
t.othoneos
LQ Newbie
 
Registered: Oct 2011
Location: Athens, Greece
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thnx colucix,

but there's an error like this:

-bash: printf: US: invalid number
67.185.84.130 36351 0
-bash: printf: US: invalid number
213.144.186.65 36351 0
 
Old 10-11-2011, 03:49 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Shouldn't it be the fourth field printed out? Anyway, just change the format of the printf statement to
Code:
"%15s %s %s %s\n"
that is all strings and it should be fine.
 
Old 10-11-2011, 03:51 PM   #5
t.othoneos
LQ Newbie
 
Registered: Oct 2011
Location: Athens, Greece
Posts: 16

Original Poster
Rep: Reputation: Disabled
My bad,

inputed the wrong file.

Worked like a charm.

Thank you very much. You saved me a tone of hours.
 
Old 10-11-2011, 03:56 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You're welcome!
 
  


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
-bash: whois: command not found neoform Linux - Newbie 11 06-08-2012 12:26 AM
whois - command not found foxxer Mandriva 5 05-28-2005 03:31 PM
Whois command sdr_ar Mandriva 2 11-20-2004 10:43 PM
whois command not found? wtf? Smokey Slackware 4 09-19-2004 09:14 AM
whois command cmenjivar Linux - Newbie 4 08-29-2001 06:52 AM


All times are GMT -5. The time now is 03:01 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