-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipBot.php
More file actions
46 lines (45 loc) · 1.45 KB
/
ipBot.php
File metadata and controls
46 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
function getLocation( $ip ){
$html = file_get_contents('http://whatismyipaddress.com/ip/'.$ip);
$dom = new DOMDocument();
@$dom->loadHTML( $html );
$xpath = new DOMXPath($dom);
$tableCol = $xpath->query('//th[@*]');
$ret = array();
foreach ($tableCol as $col){
if (strpos($col->nodeValue, 'State/Region:')){
$val = $col->nextSibling;
if(!in_array($val,$ret)){
array_push($ret,$val);
}
}
else if (strpos($col->nodeValue, 'City:')){
$val = $col->nextSibling;
if(!in_array($val,$ret)){
array_push($ret,$val);
}
}
if (strpos($col->nodeValue, 'Postal Code:')){
$val = $col->nextSibling;
if(!in_array($val,$ret)){
array_push($ret,$val);
}
}
}
return $ret;
}
function getZip( $ip ){
$browser = new SimpleBrowser();
$html = $browser->get('http://www.ipaddresslabs.com/IPGeolocationServiceDemo.do?ipaddress='.$ip.'#StandardEditionTab');
$dom = new DOMDocument();
@$dom->loadHTML( $html );
$xpath = new DOMXPath($dom);
$tableCol = $xpath->query('//td[@*]');
foreach ($tableCol as $col){
if (strpos($col->nodeValue, 'postal_code')){
$val = $col->nextSibling->nextSibling->nextSibling->nextSibling->nextSibling->nextSibling->textContent;
return $val;
}
}
}
?>