-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptp-bssid-update.pl
executable file
·148 lines (118 loc) · 3.61 KB
/
ptp-bssid-update.pl
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
142
143
144
145
146
147
148
#!/usr/bin/perl
#use strict;
use Socket;
my ($cookie,$query,@date,$datestr,$port,$iaddr,$paddr,$proto,$line);
# To use this script, discover your own auth cookie and sid and include customized expressions as commented out below:
#$cookie='phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bi%3A-1%3B%7D; auth=$YOURUSERNAME%3A786538655%3A1187426809%3AIAe%2FsXTUPOUb0C7sEpZYHw';
#phpbb2mysql_sid=$32characterHexString
$query = "POST /gps/gps/main/confirmquery/ HTTP/1.1
Host: wigle.net
Accept: text/plain
Keep-Alive: 300
Connection: keep-alive
Cookie: $cookie
Content-Type: application/x-www-form-urlencoded";
@date = localtime;
$datestr = sprintf("%04d%02d%02d-%02d%02d%02d",
$date[5]+1900,$date[4]+1,$date[3],$date[2],$date[1],$date[0]);
open(CACHE,">/tmp/ptp-bssid-update-html-$datestr") or die "open: $!";
open(RESULT,">ptp-bssid-update-download-$datestr") or die "open: $!";
$proto = getprotobyname('tcp');
$port = getservbyname('http', 'tcp');
$iaddr = inet_aton("wigle.net");
$paddr = sockaddr_in($port,$iaddr);
# query www.personaltelco
print "debug: query www.personaltelco\n";
socket(SOCK,PF_INET,SOCK_STREAM,$proto) or die "socket: $!";
connect(SOCK,$paddr) or die "connect: $!";
select(SOCK); $| = 1; select(STDOUT); # turns on autoflush for SOCK
print SOCK <<EOF;
$query
Content-Length: 34
ssid=www.personaltelco&Query=Query
EOF
shutdown(SOCK, 1);
while (<SOCK>) {
print CACHE $_;
if (/^<td>/) {
s|</td><td>|\t|g;
s|<td>||;
s|</td></tr>||;
s| ||g;
print RESULT $_;
chomp;
($netid,$network) = split /\t/, $_, 2;
$netid =~ tr/a-z/A-Z/;
$data{$netid} = $network;
}
}
close(SOCK);
print "debug: query personaltelco\n";
# query personaltelco
socket(SOCK,PF_INET,SOCK_STREAM,$proto) or die "socket: $!";
connect(SOCK,$paddr) or die "connect: $!";
select(SOCK); $| = 1; select(STDOUT); # turns on autoflush for SOCK
print SOCK <<EOF;
$query
Content-Length: 30
ssid=personaltelco&Query=Query
EOF
shutdown(SOCK, 1);
while (<SOCK>) {
print CACHE $_;
if (/^<td>/) {
s|</td><td>|\t|g;
s|<td>||;
s|</td></tr>||;
s| ||g;
print RESULT $_;
chomp;
($netid,$network) = split /\t/, $_, 2;
$netid =~ tr/a-z/A-Z/;
$data{$netid} = $network;
}
}
close(SOCK);
open(OLD,"ptp-bssid-with-notes") or die "open: $!";
while(<OLD>) {
chomp;
($bssid,@old) = split /\t/;
$bssid =~ tr/a-z/A-Z/;
$note{$bssid} = $old[$#old];
if (! defined($data{$bssid})) {
# if no new data yet, query by bssid
print "debug: querying $bssid with $note{$bssid}";
socket(SOCK,PF_INET,SOCK_STREAM,$proto) or die "socket: $!";
connect(SOCK,$paddr) or die "connect: $!";
select(SOCK); $| = 1; select(STDOUT); # turns on autoflush for SOCK
print SOCK <<EOF;
$query
Content-Length: 35
netid=$bssid&Query=Query
EOF
shutdown(SOCK, 1);
while (<SOCK>) {
print CACHE $_;
if (/^<td>/) {
s|</td><td>|\t|g;
s|<td>||;
s|</td></tr>||;
s| ||g;
print RESULT $_;
chomp;
($netid,$network) = split /\t/, $_, 2;
$netid =~ tr/a-z/A-Z/;
$data{$netid} = $network;
}
}
close(SOCK);
}
}
foreach $key (keys %data) { $merged{$key}++; }
foreach $key (keys %note) { $merged{$key}++; }
foreach $key (sort keys %merged) {
print join "\t", $key, $data{$key}, $note{$key};
print "\n";
}
close(CACHE);
exit;