-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingnetwork.m
executable file
·68 lines (58 loc) · 1.91 KB
/
pingnetwork.m
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
#!/usr/bin/octave
%sg: 21 dec 2018
% script in octave/matlab to find ip addresses on wireless network
% it's slow but seems at least much more reliable (compared to NMAP and other linux type commands)
% 23 dec 2019: added parallel computing, computational time reduced to 10 seconds (compared to several minutes)
%clc
clear variables
close all
dbstop if error
macaddress1='7c:7d:3d:ba:ef:be';
macaddress_found=false;
Npackages=2;
% use parallel computing in octave, it reduces searching by an order of magnitude
##try
## pkg load parallel
## tic
##
## ip_addresses = 2:254;
## nproc=min(ceil(length(ip_addresses)/3+5),20); %amount of parallel processes
## discovered = pararrayfun(nproc, @find_on_network, ip_addresses);
##
## I=find(discovered);
## display('ip addresses on network:')
## for i=1:length(I)
## display(['192.168.0.',num2str(ip_addresses(I(i)))])
## end
##
## toc
##
## catch
% use serial computing
tic
for i=254:-1:1
%ping ip address
str_ip=['[STATUS, OUTPUT] =system(',char(39),'ping 192.168.0.',num2str(i),' -c ',num2str(Npackages),' -W 4',char(39),');'];
eval(str_ip)
%was pinging successful?
if ~isempty(strfind(OUTPUT,[num2str(Npackages),' received'])) || ~isempty(strfind(OUTPUT,[num2str(1),' received']))
disp('*************')
disp(['192.168.0.',num2str(i)])
ipaddress=['192.168.0.',num2str(i)];
% check mac address
clear OUTPUT STATUS
temp_str=['[STATUS, OUTPUT] =system(',char(39),'arp -a | grep ',ipaddress,char(39),');'];
eval(temp_str);
if ~isempty(OUTPUT)
if ~isempty(strfind(OUTPUT,macaddress1))
disp('---------------')
display('macaddress1 found')
disp('---------------')
macaddress_found=true;
%break;
end
end
endif
end
toc
## end