LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 01: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, 02:33 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 02: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, 02:49 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 02: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, 02:56 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:54 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
Open Source Consulting | Domain Registration