-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathss-trace
executable file
·32 lines (29 loc) · 876 Bytes
/
ss-trace
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
#!/usr/bin/perl
use strict;
use Geo::IP;
my $pid = `pidof ss-server`;
chop($pid);
die "Cannot find ss-server running\n" if $pid eq "";
open my $file, "/proc/$pid/net/tcp" or die "Cannot open TCP data\n";
my %ips;
while(<$file>)
{
my ($local, $localp, $rem, $remp) = /(\w{8}):(\w{4}) (\w{8}):(\w{4}) 01 /;
next unless $local;
next unless hex($localp) == 8388;
$local = join(".", map {hex($_)} reverse($local =~ /(..)/g));
$rem = join(".", map {hex($_)} reverse($rem =~ /(..)/g));
$ips{$rem} = 1;
}
close $file;
my $gi = Geo::IP->open("/usr/share/GeoIP/GeoIPCity.dat", GEOIP_STANDARD);
my $currentIP = $ENV{'SSH_CONNECTION'};
$currentIP =~ s/\s.*//;
for my $ip(keys %ips)
{
my $rec = $gi->record_by_addr($ip);
my $city = $rec->city;
my $country = $rec->country_name;
print "*" if $currentIP eq $ip;
print "$ip $country $city\n";
}