I'm trying to write a script to find out the Country of a particular IP - and I'm very rusty.
Here is the code I have so far:
$ipaddr = "209.0.0.5";
$data = exec("whois -h whois.arin.net \"+ $ipaddr\"",$ret);
foreach($ret as $line)
{
echo "$line<br>";
}
Which displays:
[whois.arin.net]
OrgName: Level 3 Communications, Inc.
OrgID: LVLT
Address: 1025 Eldorado Blvd.
City: Broomfield
StateProv: CO
PostalCode: 80021
Country: US
NetRange: 209.0.0.0 - 209.0.255.255
CIDR: 209.0.0.0/16
NetName: LEVEL6-CIDR
NetHandle: NET-209-0-0-0-1
Parent: NET-209-0-0-0-0
NetType: Direct Allocation
NameServer: NS1.LEVEL3.NET
NameServer: NS2.LEVEL3.NET
Comment:
RegDate: 2000-03-10
Updated: 2001-05-30
TechHandle: LC-ORG-ARIN
TechName: level Communications
TechPhone: +1-877-453-8353
TechEmail: ipaddressing@level3.com
OrgAbuseHandle: APL8-ARIN
OrgAbuseName: Abuse POC LVLT
OrgAbusePhone: +1-877-453-8353
OrgAbuseEmail: abuse@level3.com
OrgTechHandle: TPL1-ARIN
OrgTechName: Tech POC LVLT
OrgTechPhone: +1-877-453-8353
OrgTechEmail: ipaddressing@level3.com
OrgTechHandle: ARINC4-ARIN
OrgTechName: ARIN Contact
OrgTechPhone: +1-800-436-8489
OrgTechEmail: arin-contact@genuity.com
ARIN WHOIS database, last updated 2003-12-29 19:15
Enter ? for additional hints on searching ARIN's WHOIS database.
I need to somehow get out and assign a variable to the country. In this case, the country is "US". For the likes of me I just can't figure out how.