-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathpi
executable file
·90 lines (78 loc) · 1.92 KB
/
pi
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
#!/usr/bin/perl
# nmap -sn 192.168.1.0/24
use Socket;
# discover and ssh to any raspberry pi on your network
# -samy
# alfa 0:c0:ca:
my $opts = ($0 =~ /pix$/i ? "-X" : "");
my $bbb = ($0 =~ /bb/i);
my $MAC = '(b8:27:eb|80:1f:0?2|74:da:38|00?:c0:ca)';
my @defdevs = qw/bridge0 en0 en1 bridge100 vnic0 vnic1/;
if ($ARGV[0] =~ /:/i)
{
$MAC = shift $ARGV[0];
}
elsif ($ARGV[0] =~ /iphone/)
{
$MAC = "80:be:5:3b:68:91";
}
else
{
@devs = @ARGV ? @ARGV : @defdevs;
}
#arp();
foreach my $dev (@devs)
{
my ($ip) = `ifconfig $dev` =~ /inet\s+(\S+)\.\d+\s/;
if ($ip)
{
print "Scanning $dev $ip.0/24\n";
foreach (0 .. 255)
{
socket my $s, PF_INET, SOCK_DGRAM, 0;
connect $s, pack_sockaddr_in(1, inet_aton("$ip.$_"));
syswrite $s, 1, 1;
}
sleep(1);
arp();
}
}
sub arp
{
my $match;
my @arp = `arp -na`;
foreach (grep { /\((.*?)\)\s+at\s+$MAC/g } @arp)
{
# print "^$1^ $_";
print;
$match ||= (/\((.*?)\)/)[0];
}
#my ($match) = `arp -na` =~ /\((.*?)\)\s+at\s+$MAC/;
if ($match)
{
my $ssh = "ssh $opts pi\@$match";
print "\n$ssh\n\n";
exec($ssh);
exit;
}
}
__DATA__
tigerblood:/Users/samy/code$ ifconfig en1
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether e0:f8:47:00:98:82
inet6 fe80::e2f8:47ff:fe00:9882%en1 prefixlen 64 scopeid 0x5
inet 10.0.1.32 netmask 0xffffff00 broadcast 10.0.1.255
media: autoselect
status: active
tigerblood:/Users/samy/code$ ifconfig bridge0
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether ac:de:48:c2:90:b4
inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
Configuration:
priority 0 hellotime 0 fwddelay 0 maxage 0
ipfilter disabled flags 0x2
member: en0 flags=3<LEARNING,DISCOVER>
port 4 priority 0 path cost 0
Address cache (max cache: 100, timeout: 1200):
b8:27:eb:85:69:a2 en0 1179 flags=0<>
? (192.168.2.8) at b8:27:eb:85:69:a2 on bridge0 ifscope [bridge]