forked from samyk/samytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktopinfo
executable file
·121 lines (106 loc) · 2.14 KB
/
desktopinfo
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
#!/usr/bin/perl
use strict;
# sniff
if ($ARGV[0] eq "-s")
{
exit;
my $ip = `/sbin/ifconfig en1`;
$ip = $1 if $ip =~ /inet (\S+)/;
system("tcpdump -i en1 'not host $ip and not port 139 and not port 137 and not port 138 and not port snmp and not arp and not icmp and not igmp and not port microsoft-ds and not ssdp and not port mdns and (tcp or port 53)'");
}
# sniff eth
elsif ($ARGV[0] eq "-e")
{
open F, "</tmp/.dt.macs";
print while <F>;
close F;
close STDOUT;
close STDERR;
fork && exit;
my %macs;
open O, "</Users/samy/Documents/.oui.txt";
while (<O>)
{
if (/^(\w{6})\s+\(.*?\)\s+(\S.*)$/)
{
s/\r//g;
$macs{$1} = $2;
}
}
close(O);
my $ip = `/sbin/ifconfig en1`;
$ip = $1 if $ip =~ /inet (\S+)/;
open G, "</tmp/.dt.ip";
chomp(my $oldip = <G>);
close(G);
my %found;
if ($oldip ne $ip)
{
open G, ">/tmp/.dt.ip";
print G "$ip\n";
close G;
open F, ">/tmp/.dt.macs";
}
else
{
open F, "</tmp/.dt.macs";
while (<F>)
{
/^(\S+)/ && $found{$1}++;
}
close F;
open F, ">>/tmp/.dt.macs";
}
eval
{
my $pid = open TCP, "tcpdump -levvvi en1 'not host $ip' 2>>/dev/null|";
alarm(60);
$SIG{ALRM} = sub { kill 2, $pid; close(F); die; };
while (<TCP>)
{
if (/^\s*\S+\s+((\w+:\w+:\w+)\S+).*?((\w+:\w+:\w+)\S+).*?\s(\d+.\d+\.\d+\.\d+)\.(\S+) > (\d+.\d+\.\d+\.\d+)\.(\S+)/)
{
my ($eth1, $oui1, $eth2, $oui2, $ip1, $port1, $ip2, $port2) = ($1, $2, $3, $4, $5, $6, $7, $8);
$oui1 =~ s/://g;
$oui1 = uc($oui1);
$oui2 =~ s/://g;
$oui2 = uc($oui2);
if (!$found{$ip1}++)
{
print F "$ip1\t$eth1\t$macs{$oui1}\n";
}
if (!$found{$ip2}++)
{
print F "$ip2\t$eth2\t$macs{$oui2}\n";
}
}
}
};
system("clear");
open F, "</tmp/.dt.macs";
print while <F>;
close F;
}
# normal info
else
{
system("uptime");
print "\n";
my $air = `airport -s`;
$air =~ s| \(auth/unicast/group\)||;
my @air = split /\n/, $air;
my $chars = 100;
foreach (@air)
{
if (/^(\s+)\S/)
{
$chars = length($1) if length($1) < $chars;
}
}
$air =~ s/^ {$chars}//mg;
$air =~ s/\n.*?IBSS network.*?found.*?\n/\n/m;
print $air;
print "\n";
system("airport -I");
print "\n";
}