-
Notifications
You must be signed in to change notification settings - Fork 0
/
anal-network-listInterfaces.pl
executable file
·47 lines (42 loc) · 1.11 KB
/
anal-network-listInterfaces.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
#!/usr/bin/perl
use JSON;
sub asQuotedString
{
my ($str) = @_;
$str =~ s/\\/\\\\/g;
$str =~ s/\"/\\\"/g;
return '"' . $str . '"';
}
sub dhcpcdIsRunning
{
my ($arg) = @_;
return `pgrep -f 'dhcpcd.*$arg'`;
}
$output = `ip -j -p address`;
$result = decode_json($output);
foreach $elt (@$result) {
if (grep /^UP$/, @{$elt->{'flags'}}) {
$elt->{'up'} = '1';
} else {
$elt->{'up'} = '0';
}
if (grep /^LOWER_UP$/, @{$elt->{'flags'}}) {
$elt->{'lowerUp'} = '1';
} else {
$elt->{'lowerUp'} = '0';
}
$address = '';
foreach $addrelt (@{$elt->{'addr_info'}}) {
if ($addrelt->{'family'} eq 'inet') {
$address = $addrelt->{'local'};
last;
}
}
$elt->{'dhcpcdIsRunning'} = '0';
if ($elt->{'ifname'}) {
if (dhcpcdIsRunning($elt->{'ifname'})) {
$elt->{'dhcpcdIsRunning'} = '1';
}
}
print "interface:$elt->{'ifname'} type:$elt->{'link_type'} up:$elt->{'up'} lowerUp:$elt->{'lowerUp'} operstate:$elt->{'operstate'} address:$address dhcpIsRunning:$elt->{'dhcpcdIsRunning'}\n";
}