-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.php
More file actions
37 lines (32 loc) · 790 Bytes
/
Copy pathsum.php
File metadata and controls
37 lines (32 loc) · 790 Bytes
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
<?php
$f = fopen('/home/sylee/IPMN_log/IPMN_ip_201201.txt', 'r');
$ip = [];
while ($r = fgets($f)) $ip[] = trim($r);
$mysqli = new mysqli('localhost', 'root', 'bibs@)!$', 'bibsv2');
$latlon = "latlon.csv";
$f = fopen($latlon, "r");
$h = fgetcsv($f);
$ll = [];
while ($r = fgetcsv($f)) {
$ll[$r[1]] = $r;
}
fclose($f);
$uu = array();
$dd = array();
foreach ($ip as $v) {
if (isset($dd[$v]))
$rr = $dd[$v];
else {
$q = "SELECT country FROM `ip2nation` WHERE ip < INET_ATON('".$v."') ORDER BY ip DESC LIMIT 1";
//echo $q;
$rr = $mysqli->query($q)->fetch_row()[0];
$dd[$v] = $rr;
}
if (!isset($uu[$rr])) $uu[$rr] = 0;
$uu[$rr]++;
}
echo "Lat Lon Title Value\n";
foreach ($uu as $k=>$v) {
$lalo = $ll[strtoupper($k)];
echo $lalo[4]."\t".$lalo[5]."\t".$lalo[0]."\t$v\n";
}