|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 11:00 AM.. Reason: code tags, PLEASE! |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
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 $ |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
Thanks.
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using 'whois' to Retrieve all IPs/Subnets for an Organization | deckard | IP Networking | 0 | 09-25-2009 11:38 AM |
| whois scripting | stesecci | Shell Programming and Scripting | 1 | 11-07-2008 08:45 AM |
| whois VS jwhois and timeout | PWSwebmaster | Shell Programming and Scripting | 4 | 02-15-2008 01:54 AM |
| Traceroute and Whois mystery | DumDum | IP Networking | 2 | 07-03-2002 11:24 PM |
|
|