whois country help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting whois country help
# 1  
Old 05-16-2010
whois country help

Hello folks,

I have list of ips like

Code:
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4


Code:
whois 1.1.1.1 |grep -E 'country|Country'

it show country=US or whatever.

so i have number of ips in text file, how i can use above script to automate output like

Code:
1.1.1.1 US
2.2.2.2 CA
3.3.3.3 FR



---------- Post updated at 09:16 AM ---------- Previous update was at 09:04 AM ----------

Code:
#!/bin/sh

while read inputline
do
  country=`whois $inputline|grep -E 'country|Country'`
   echo $inputline $country
done < /ip.txt

exit 0

i have done it like that, is there any other suggestion

---------- Post updated at 09:22 AM ---------- Previous update was at 09:16 AM ----------

in same file of ips, i have ips with hits like

Code:
50 1.1.1.1
40 2.2.2.2
30 3.3.3.3
15 4.4.4.4

how can i see its output like that with above script

Code:
IP=1.1.1.1 Country=1.1.1.1 Hits=50
IP=2.2.2.2 Country=2.2.2.2 Hits=40


Last edited by vgersh99; 05-16-2010 at 01:00 PM.. Reason: code tags, PLEASE!
# 2  
Old 05-16-2010
Does you script actually work? I keep experiencing that almost every whois query returns two country codes. I think the first is the code for the whois server itself (not sure), and the second for the ip which is being queried. Some whois queries don't have any country code. However following while loop works pretty nice for me:
Code:
$ cat iplist
202 xxx.xxx.xxx.x
22 xxx.xx.xx.x
71 xx.xx.xxx.xx
112 xxx.xx.x.x
$ while read hits ip; do
country=$(whois "$ip" | grep -E '[Cc]ountry' | sed 's/[Cc]ountry: *//' | tr "\n" ",")
echo -n "IP=$ip Country=$country Hits=$hits" && echo
done <iplist | sed 's/, H/ H/'
IP=xxx.xxx.xxx.x Country=NL,AT Hits=202
IP=xxx.xx.xx.x Country= Hits=22
IP=xx.xx.xxx.xx Country=NL,FR Hits=71
IP=xxx.xx.x.x Country=NL,IT Hits=112
$

# 3  
Old 05-16-2010
Code:
while read hits ip
do
   country=$(whois $ip | awk 'tolower($1) == "country:" { print $2 }')
   echo "IP=$ip  Country=$country  Hits=$hits"
done < iplist

# 4  
Old 05-16-2010
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. What is on Your Mind?

Whois Lookup

Hi. I've just made our internal Whois lookup service available for all forum users, not only moderators and admins. Whois Database It's basically the same whois info you can get from your command line and many other web sites. If you would like to see other features, please post in... (0 Replies)
Discussion started by: Neo
0 Replies

2. IP Networking

Whois or nslookup.. for domain availability?

Hi, i want to make linux bash script which will periodically check for certain domain availability, i mean like every 100miliseconds. I want to ask which command i need to use, so the result is not cached and i dont cause any inappropriate overload? i see: whois domainname.com (when No... (1 Reply)
Discussion started by: postcd
1 Replies

3. Shell Programming and Scripting

How to obtain info from whois?

Hello, do you know any clever way to get information whether certain domain name become avaialble for registration from bash script? Would be good to check for the availability like every 100miliseconds, i want to catch domain. (1 Reply)
Discussion started by: postcd
1 Replies

4. UNIX for Dummies Questions & Answers

How can I do whois -r with a input file?

Hello, I was wondering how I can do a whois from a file with lots of ip's in this format 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 And so on, then print the whois data from all the ip's to one single file sort of like this "whois -r 'ipfile' > 'whoisfile'" Thanks in advance! ... (3 Replies)
Discussion started by: uxfuser
3 Replies

5. Shell Programming and Scripting

whois scripting

Hi guys, I need a script that given an IP address, say IPA, do the following: - queries "whois IPA" - extracts, from the whois answer, the IP network string indicated after the string "route:", - searches the IP network string in a given text file, say CIDR2ASN.txt, which has several lines,... (1 Reply)
Discussion started by: stesecci
1 Replies

6. Shell Programming and Scripting

whois VS jwhois and timeout

I have a script that does a whois lookup that worked fine on a previous server. It used whois with the t option to timeout in 5 seconds. A while back I upgraded to a new server and the script had problems. I found out the new server didn't even have whois. The whois command was symlinked to jwhois... (4 Replies)
Discussion started by: PWSwebmaster
4 Replies

7. IP Networking

Traceroute and Whois mystery

Hey folks, I've been charged with the job of finding out who's been screwing around with the download counts on our site. So now I have this huge list of IP's that I supposed to match to such and such developer. I was told by one guy that I should just do a traceroute and that'd tell me where... (2 Replies)
Discussion started by: DumDum
2 Replies
Login or Register to Ask a Question