forked from tactmaster/HECT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetips.php
141 lines (113 loc) · 3.46 KB
/
getips.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/*
Gets all the ip from "http://sixy.ch/feed" and put the in ips.cvs
*/
function getIPs($currentdir,$debug)
{
if ($debug) print "RSS Check ";
// Old method
// $xml= simplexml_load_file("http://sixy.ch/feed");
//Doing stuff to get round php new secruty resistions
//Have long wait for timeout for some reason getting to sixy was slow at time of testing
$xml = loadXML2("sixy.ch","/feed", 100);
touch($currentdir."ip.csv");
if ($xml && !empty($xml))
{
foreach($xml->entry as $entry) {
$title = base64_encode($entry->title);
//getting ip from dig
$arip = preg_split("/((?<!\\\|\r)\n)|((?<!\\\)\r\n)/",trim(shell_exec("dig $entry->title AAAA +short")));
//may have multiply ips so adds them a different entries.
foreach($arip as $ipraw)
{
$ipcheck = filter_var($ipraw, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
//print $ipraw." ".$ipcheck."\n";
$ip = base64_encode($ipcheck);
// checking to see if ip alread in list. MASSIVELY INEFFICENT. however should be ok as small number of entires. DB better here.
if ($ip != "" && $title != "")
{
$iphandle = fopen($currentdir."ip.csv", "r");
$found = 0;
// print "founding:$ip \n";
do
{
$ipdata = fgetcsv($iphandle);
if ($ipdata[0] == $title && $ipdata[1] == $ip)
{
// print "found:$title $ip \n";
$found = 1;
break;
}
} while (count($ipdata) == 2);
fclose($iphandle);
if (!$found)
{
if ($debug) print "adding:$entry->title $ipcheck $title $ip \n";
$handle = fopen($currentdir."ip.csv", "a");
fwrite($handle,$title.','.$ip."\n");
fclose($handle);
}
}
//echo $title."-".$ip."-\n";
}
}
} else
{
if ($debug){
print "Feed download failed\n";
var_dump($xml);
}
}
$count = 0;
$iphandle = fopen($currentdir."ip.csv", "r");
$ipdata = fgetcsv($iphandle);
while (count($ipdata) == 2)
{
// print "Counting...:".$count."\n";
$ipdata = fgetcsv($iphandle);
$count++;
}
fclose($iphandle);
if ($debug) print "Count:".$count."\n";
}
/*
from http://de2.php.net/manual/en/function.simplexml-load-file.php
thanks to jamie at splooshmedia dot co dot uk
*/
function loadXML2($domain, $path, $timeout = 30) {
/*
Usage:
$xml = loadXML2("127.0.0.1", "/path/to/xml/server.php?code=do_something");
if($xml) {
// xml doc loaded
} else {
// failed. show friendly error message.
}
*/
$fp = fsockopen($domain, 80, $errno, $errstr, $timeout);
if($fp) {
// make request
$out = "GET $path HTTP/1.1\r\n"; ;
$out .= "Host: $domain\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
// get response
$resp = "";
while (!feof($fp)) {
$resp .= fgets($fp, 128);
}
// check status is 200
$status_regex = "/HTTP\/1\.\d\s(\d+)/";
if(preg_match($status_regex, $resp, $matches) && $matches[1] == 200) {
// load xml as object
$parts = explode("\r\n\r\n", $resp);
//print $parts[1];
$data = explode('<?xml version="1.0" encoding="utf-8"?>',$resp);
//var_dump($data);
$feed = explode('</feed>',$data[1]);
return simplexml_load_string('<?xml version="1.0" encoding="utf-8"?>'.$feed[0].'</feed>');
}
}
return false;
}
?>