#!/usr/bin/perl -w # needs packages: # apt-get install libjson-perl libwww-perl iptables use strict; use Data::Dumper; use Time::HiRes qw (gettimeofday tv_interval); use JSON; use LWP; my $verbose = 0; my $daemon = 0; my $do_pager = 1; my %ifs = (); my %routes = (); my $my_id; sub docmd; sub sort_routes; while ($_ = shift @ARGV) { m/-v/ && do { $verbose++; next; }; m/-d/ && do { $daemon++; $my_id = shift @ARGV; next; }; m/-n/ && do { $do_pager = 0; next; }; m/-p/ && do { $do_pager++; next; }; do_command($_); } if ($daemon) { if (!$my_id) { $my_id = `hostname`; chomp $my_id; } for (;;) { gather_ip(); my $updated_time = [gettimeofday()]; update_mbps($updated_time); my $uptime = (split(/\s+/, `cat /proc/uptime`))[0]; my $upload_record = {id => $my_id, time => $updated_time, ifs => \%ifs, uptime => $uptime}; my $get_temp = "/root/bin/get_temp.$my_id"; if (-x $get_temp) { my $temp = `$get_temp`; chomp $temp; $upload_record->{temp} = $temp; } my $json = to_json($upload_record); my $req = HTTP::Request->new('POST', "http://e:1080/nets/nets.php?req=update&id=$my_id"); $req->header('Content-Type' => 'application/json'); $req->content($json); my $lwp = LWP::UserAgent->new; my $r = $lwp->request($req); my $content = $r->content; chomp($content); printf("[%d.%06d] %s %s %s\n", @$updated_time, $r->code, $r->message, $content); for my $if_name (sort keys %ifs) { next; my $if = $ifs{$if_name}; next if $if->{nr} == 1; my $addr = $if->{first_ip}; next unless $addr; my $wlan = sprintf("(%s%s)", $if->{ssid} ? $if->{ssid} : "", $if->{mbps} ? sprintf(" %dM", $if->{mbps}) : ""); my $addr_ = sprintf("%s%s", $addr, $if->{peer} ? " --> $if->{peer}" : ""); my $info = sprintf("%s%s", $addr_, $if->{ssid} ? $wlan : ""); printf("%s %s", $if_name, $info); printf(" %g", $if->{tx_rate} ? $if->{tx_rate} : 0); printf(" %g", $if->{rx_rate} ? $if->{rx_rate} : 0); print "\n"; } sleep 60; } } if ($do_pager) { open(OUT, "| less -E") or die; *STDOUT = *STDERR = *OUT; } print "HOST\n ", docmd "hostname"; ################################################ # All types of virtual environments ################################################ print "CPU\n"; -X "/usr/bin/virsh" && do { my $n = grok("virsh nodeinfo | fgrep :"); my $mem = (split(/ /, $n->{'Memory size'}))[0]; my $freq = (split(/ /, $n->{'CPU frequency'}))[0]; printf(" %-10s %.1fGHz %.1fGb RAM %d sock %d cores %d threads\n", $n->{'CPU model'}, $freq / 1e3, $mem / 1024 / 1204, $n->{'CPU socket(s)'}, $n->{'CPU socket(s)'} * $n->{'Core(s) per socket'}, $n->{'CPU socket(s)'} * $n->{'Core(s) per socket'} * $n->{'Thread(s) per core'}, ); my $already = 0; for (docmd "virsh -q list") { print "KVM\n" unless $already++; m/\S+\s+(\S+)\s+/ && do { print " $1\n"; }; } }; do { my $n = grok("cat /proc/cpuinfo"); my $m = grok("free"); printf(" %s %.2fGB RAM", $n->{'model name'}, (split(/\s+/, $m->{'Mem'}))[0] / 1024 / 1024); printf(" %d cores %d threads %s L3 cache\n", $n->{'cpu cores'}, $n->{'siblings'}, $n->{'cache size'}, ) if $n->{'cpu cores'}; print "\n"; }; # CPU model: x86_64 # CPU(s): 4 # CPU frequency: 3193 MHz # CPU socket(s): 1 # Core(s) per socket: 2 # Thread(s) per core: 2 # NUMA cell(s): 1 # Memory size: 3842308 kB # total used free shared buffers cached # Mem: 3883040 3730920 152120 347004 14196 960044 # -/+ buffers/cache: 2756680 1126360 # Swap: 4028412 4019488 8924 # processor : 0 # vendor_id : GenuineIntel # cpu family : 6 # model : 58 # model name : Intel(R) Core(TM) i3-3217U CPU @ 1.80GHz # stepping : 9 # microcode : 0x12 # cpu MHz : 774.000 # cache size : 3072 KB # physical id : 0 # siblings : 4 # core id : 0 # cpu cores : 2 # apicid : 0 # initial apicid : 0 # fpu : yes # fpu_exception : yes # cpuid level : 13 # wp : yes # flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx f16c lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms # bogomips : 3591.81 # clflush size : 64 # cache_alignment : 64 # address sizes : 36 bits physical, 48 bits virtual # power management: print "KERN\n ", docmd "uname -r"; -X "/usr/bin/vboxmanage" && do { my $already = 0; for(docmd "/usr/bin/vboxmanage list runningvms") { print "VirtualBox\n" unless $already++; m/\"(\S+)\" / && do { print " $1\n"; }; } }; -X "/usr/bin/lxc-ls" && do { my $already = 0; my $i_option = "-i"; $i_option = "" if docmd("lxc-info -i 2>&1 | fgrep invalid") =~ m/invalid/; for my $path ("/var/lib/lxc", ) { for (docmd "lxc-ls -P $path 2>&1") { chomp; my ($state, $pid); my @ips; last if m/^lxc: /; for (docmd "lxc-info -P $path -n $_ $i_option -p -s 2>&1") { chomp; m/[Ss]tate:\s+(\S+)/ && do { $state = $1; }; m/[Pp][Ii][Dd]:\s+(\S+)/ && do { $pid = $1; }; m/IP:\s+(\S+)/ && do { push(@ips, $1); }; } print "LXC\n" unless $already++; printf(" %-10s %s%s %s\n", $_, $state, $pid ? "($pid)" : "", join(", ", @ips)); } } }; ################################################ # vnc servers ################################################ my @vnc_servers; for (docmd "/bin/netstat -pan 2>&1 | /bin/fgrep -i vnc") { m/^tcp/ && do { my ($proto, $sendq, $recvq, $loc_s, $rem_s, $state, $proc) = split; my ($la, $lp) = split(/:/, $loc_s); my ($ra, $rp) = split(/:/, $rem_s); if($state eq "LISTEN") { next if $lp >= 6000; push(@vnc_servers, sprintf(":%d", $lp - 5900)); } }; } print "VNC\n serve ", join(" ", @vnc_servers), "\n" if ($#vnc_servers >= 0); ################################################ # bridges ################################################ -X "/sbin/brctl" && do { my @bridges; for (docmd "brctl show") { my @a = split /\s+/; next if $a[0] eq "bridge"; push(@bridges, $a[0]) if $a[0]; } print "BRIDGES\n" if $#bridges >= 0; for (@bridges) { my @ports; for (docmd "brctl show $_") { my @a = split /\s+/; next if $a[0] eq "bridge"; next unless $a[3] || $#a == 1; push (@ports, $a[3] ? $a[3] : $a[1]); } printf(" %-10s %s\n", $_, join(", ", @ports)); } }; # bridge name bridge id STP enabled interfaces # br0 8000.00270e1041a7 no eth0 # vnet0 # vnet2 # vnet3 # vnet4 # lxcbr0 8000.000000000000 no # virbr0 8000.000000000000 yes ################################################ # interfaces & routes, including wifi ################################################ print "IP\n"; printf(" forwarding %s\n", docmd("/bin/cat /proc/sys/net/ipv4/ip_forward") =~ m/1/ ? "ON" : "OFF"); # look at NAT table my $masq = 0; for (docmd "/sbin/iptables -L -vn -t nat") { m{^\s*\S+\s+\S+\s+MASQUERADE\s+all.+0\.0\.0\.0/0.+0\.0\.0\.0/0} && do { $masq++; last; }; } printf(" NAT %s\n", $masq ? "ON" : "OFF"); # Chain PREROUTING (policy ACCEPT 1648K packets, 101M bytes) # pkts bytes target prot opt in out source destination # # Chain INPUT (policy ACCEPT 1247K packets, 81M bytes) # pkts bytes target prot opt in out source destination # # Chain OUTPUT (policy ACCEPT 47186 packets, 4139K bytes) # pkts bytes target prot opt in out source destination # # Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes) # pkts bytes target prot opt in out source destination # 90738 8085K MASQUERADE all -- * * 0.0.0.0/0 0.0.0.0/0 # 0 0 MASQUERADE all -- * * 10.0.3.0/24 !10.0.3.0/24 sub gather_ip { # temporarily mark all previously know interfaces as gone so we can tell if they went away map { $ifs{$_}->{present} = 0 } keys %ifs; for (docmd "/sbin/ip -o a") { m/(\d+)(:|) (\S+)\s+inet (\S+) (\S+) (\S+)/ && do { my ($if_nr, $if_name, $if_addr, $arg1, $arg2) = ($1, $3, $4, $5, $6); $ifs{$if_name} = {} unless $ifs{$if_name}; my $if = $ifs{$if_name}; $if->{present}++; $if->{nr} = $if_nr; $if->{addr}->{$if_addr} = $if_nr; $if->{first_ip} = $if_addr unless $if->{first_ip}; if ($arg1 eq "peer") { $arg2 =~ s{(\S+)/.*}{$1}; $if->{peer} = $arg2; } next; }; m/(\d+):\s+(\S+)\s+inet6/ && do { next; }; m/(\d+):\s+(\S+).+ link/ && do { next; }; die "HUH: $_"; } # 1: lo: mtu 16436 qdisc noqueue state UNKNOWN \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # 1: lo inet 127.0.0.1/8 scope host lo # 1: lo inet6 ::1/128 scope host \ valid_lft forever preferred_lft forever # 2: eth0: mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000\ link/ether 08:00:27:40:f8:41 brd ff:ff:ff:ff:ff:ff # 2: eth0 inet6 fe80::a00:27ff:fe40:f841/64 scope link \ valid_lft forever preferred_lft forever # 3: br0: mtu 1500 qdisc noqueue state UP \ link/ether 08:00:27:40:f8:41 brd ff:ff:ff:ff:ff:ff # 3: br0 inet 192.168.1.10/24 brd 192.168.1.255 scope global br0 # 3: br0 inet6 fe80::a00:27ff:fe40:f841/64 scope link \ valid_lft forever preferred_lft forever # 4: tap0: mtu 1500 qdisc pfifo_fast master br0 state UP qlen 100\ link/ether 66:e2:0f:a8:10:db brd ff:ff:ff:ff:ff:ff # 4: tap0 inet6 fe80::64e2:fff:fea8:10db/64 scope link \ valid_lft forever preferred_lft forever # 8: tun0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100\ link/none # 8: tun0 inet 192.168.3.1 peer 192.168.3.2/32 scope global tun0 # 9: tun1: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100\ link/none # 9: tun1 inet 192.168.13.1 peer 192.168.13.2/32 scope global tun1 %routes = (); for (docmd "/sbin/ip r") { m/(\S+) via (\S+) dev (\S+)/ && do { my ($net, $next_hop, $dev) = ($1, $2, $3); my $if = $ifs{$dev}; next unless $if; $if->{routes}->{$net}->{next_hop} = $next_hop; $net .= "_1" if $routes{$net}; $routes{$net} = "via $next_hop ($dev)"; next; }; m/(\S+) dev (\S+)/ && do { my ($host, $dev) = ($1, $2); my $if = $ifs{$dev}; next unless $if; $if->{routes}->{$host}->{dev} = $dev; $routes{$host} = "dev $dev"; next; }; die "HUH: $_"; } # gather wlan info as relevant if (-X "x/sbin/iw") { for my $if_name (keys %ifs) { my $gp = grok("/sbin/iw $if_name station dump | fgrep -v Station"); $ifs{$if_name}->{mbps} = (split(/\s+/, $gp->{'tx bitrate'}))[0] if $gp && $gp->{'tx bitrate'}; $gp = grok("/sbin/iw $if_name scan dump | fgrep -v 'on $if_name' | fgrep ':'"); $ifs{$if_name}->{ssid} = $gp->{SSID} if $gp && $gp->{SSID}; } } else { for my $if_name (keys %ifs) { my $gp = grok("/sbin/iwconfig $if_name | /bin/sed -e 's/ /\\n/g'"); next unless $gp->{ESSID}; my $ssid = substr($gp->{ESSID}, 1, -1); $ifs{$if_name}->{ssid} = $ssid; $ifs{$if_name}->{mbps} = (split(/\s+/, $gp->{'Bit Rate'}))[0] if $gp->{'Bit Rate'}; } }; # wlan0 IEEE 802.11g ESSID:"bilinear" # Mode:Managed Frequency:2.462 GHz Access Point: 00:24:B2:06:0B:08 # Bit Rate=54 Mb/s Tx-Power=27 dBm # Retry min limit:7 RTS thr:off Fragment thr=2352 B # Encryption key:A224-BB98-055A-1B0E-2517-A2C9-9F12-9BC4-30B5-D0B7-846C-3EE9-12AC-7D9B-C85C-5C54 [2] # Link Quality=87/100 Signal level=-60 dBm Noise level=-69 dBm # Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 # Tx excessive retries:0 Invalid misc:0 Missed beacon:0 # look at layer 2 for (docmd "/sbin/ip -o l") { m{(\d+): ([^:]+): <(.+)>.+state (\S+).+link/(\S+)(.*)} && do { my ($if_nr, $if_name, $if_flags, $if_state, $if_type, $rest) = ($1, $2, $3, $4, $5, $6); $ifs{$if_name} = {} unless $ifs{$if_name}; my $if = $ifs{$if_name}; $if->{nr} = $if_nr; $if->{present}++; $rest =~ m{ (.+) brd.*} && do { $if->{mac} = $1; }; my %flags = map {$_ => 1} split(/,/, $if_flags); for (docmd "/sbin/mii-tool $if_name 2>&1") { m{$if_name: negotiated (.*) flow-control, link (\S+)} && do { $if->{mii} = $1; }; } $if->{state} = $if_state; $if->{flags} = \%flags; $if->{type} = $if_type; next; }; die "HUH: $_"; } # purge any interfaces that have gone away for (keys %ifs) { if (!$ifs{$_}->{present}) { delete $ifs{$_}; print "GONE $_\n"; } } } # 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # 2: eth0: mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000\ link/ether 00:30:18:a5:f8:21 brd ff:ff:ff:ff:ff:ff # 3: eth1: mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000\ link/ether 00:30:18:a5:f8:22 brd ff:ff:ff:ff:ff:ff # 4: br0: mtu 1500 qdisc noqueue state UP mode DEFAULT group default \ link/ether 00:30:18:a5:f8:21 brd ff:ff:ff:ff:ff:ff # 5: lxcbr0: mtu 1500 qdisc noqueue state UP mode DEFAULT group default \ link/ether fe:10:0d:0c:2f:76 brd ff:ff:ff:ff:ff:ff # 13: vethA2Y1DD: mtu 1500 qdisc pfifo_fast master lxcbr0 state UP mode DEFAULT group default qlen 1000\ link/ether fe:a6:1b:b2:e3:3e brd ff:ff:ff:ff:ff:ff # 15: vethXMRR47: mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000\ link/ether fe:35:19:05:45:e4 brd ff:ff:ff:ff:ff:ff # 17: veth858JPK: mtu 1500 qdisc pfifo_fast master lxcbr0 state UP mode DEFAULT group default qlen 1000\ link/ether fe:10:0d:0c:2f:76 brd ff:ff:ff:ff:ff:ff # 19: vethR43MIA: mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000\ link/ether fe:e9:8d:d7:fb:80 brd ff:ff:ff:ff:ff:ff # 114: ppp0: mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 3\ link/ppp # 115: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default \ link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff # 116: ppp1: mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 3\ link/ppp # 119: eth1: mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000\ link/ether 3e:d0:f8:8f:7f:93 brd ff:ff:ff:ff:ff:ff sub update_mbps { my $t1 = shift; for (docmd("cat /proc/net/dev")) { s/^\s+//; my @a = split(/\s+/, $_); $a[0] =~ m/(\S+):/ && do { my $if = $ifs{$1}; next unless $if; my $rx_bytes = $a[1]; my $tx_bytes = $a[9]; if ($if->{t0}) { my $elapsed = tv_interval($if->{t0}, $t1); if ($elapsed) { $if->{rx_rate} = ($rx_bytes - $if->{rx_bytes}) / $elapsed * 8 / 1e6; $if->{tx_rate} = ($tx_bytes - $if->{tx_bytes}) / $elapsed * 8 / 1e6; } } $if->{t0} = $t1; $if->{rx_bytes} = $rx_bytes; $if->{tx_bytes} = $tx_bytes; } } } # Inter-| Receive | Transmit # face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed # br0: 10816993723 44085245 0 0 0 0 0 0 195434422458 39563000 0 0 0 0 0 0 # nl0: 5820788024 9902068 0 0 0 0 0 0 815143320 7522942 0 0 0 0 0 0 # ppp0: 1835729749 3877344 0 0 0 0 0 0 611199067 3635699 0 0 0 0 0 0 # eth0: 12495353553 49782728 0 0 0 0 0 3958721 203684934784 155149807 0 0 0 0 0 0 # eth3: 342439950 1052378 0 0 0 0 0 0 294480580 1381451 0 0 0 0 0 0 # lo: 191708464200 17812782 0 0 0 0 0 0 191708464200 17812782 0 0 0 0 0 0 # lxcbr0: 0 0 0 0 0 0 0 0 764662 3635 0 0 0 0 0 0 # tap0: 1573806028 3700241 0 0 0 0 0 0 373490664 3363515 0 0 0 0 0 0 # wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # docker0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gather_ip(); # now display what we know about the interfaces for my $if_name (sort keys %ifs) { my $if = $ifs{$if_name}; print "IF $if_name ", Dumper($if) unless 1; next if $if->{nr} == 1; my $extra = undef; -e "/run/$if_name.pid" && do { my $pid = docmd "cat /run/$if_name.pid"; chomp($pid); $extra = sprintf("%s ", join(' ', split(/\000/, docmd "cat /proc/$pid/cmdline"))); }; my $routes_shown = 0; for my $addr (sort keys %{$if->{addr}}) { my $wlan = sprintf("(%s%s)", $if->{ssid} ? $if->{ssid} : "", $if->{mbps} ? sprintf(" %dM", $if->{mbps}) : ""); my $addr_ = sprintf("%s%s", $addr, $if->{peer} ? " --> $if->{peer} " : ""); my $info = sprintf("%s%s", $addr_, $if->{ssid} ? $wlan : ""); printf(" %-10s %-32s%s", $if_name, $info, $extra ? $extra : ""); if ($routes_shown++) { print "\n"; next; } my @routes; for my $cidr (keys %{$if->{routes}}) { my $r = $if->{routes}->{$cidr}; if ($r->{next_hop} && ($if->{peer} && $r->{next_hop} ne $if->{peer} || !$if->{peer})) { push(@routes, "$cidr($r->{next_hop})"); } else { push(@routes, $cidr); } } print "routes " if ($#routes >= 0); print join(", ", @routes), "\n"; } } print "ROUTES\n"; for my $route (sort sort_routes keys %routes) { printf(" %-18s %s\n", $route, $routes{$route}); } sub sort_routes { return -1 if $a =~ m/default/; return 1 if $b =~ m/default/; my @a = split(/[.\/]/, $a); my @b = split(/[.\/]/, $b); for (my $i = 0; $i <= $#a; $i++) { return $a[$i] <=> $b[$i] if $a[$i] <=> $b[$i]; } return $a <=> $b; } print "MAC-LINK\n"; for my $if_name (sort keys %ifs) { my $if = $ifs{$if_name}; next unless defined($if->{nr}); next if $if->{nr} == 1; next unless $if->{type}; next if $if->{type} eq "ppp"; next if $if->{type} eq "none"; do { my $info = sprintf("%s (%s%s)", $if->{state}, $if->{flags}->{LOWER_UP} ? "link up" : "link down", $if->{mii} ? ", negotiated $if->{mii}" : ""); printf(" %-10s %-32s%s\n", $if_name, "[$if->{mac}]", $info); }; # if !$if->{addr} || $#{$if->{addr}} == -1; } sub grok { my $cmd = shift; print "GROK $cmd\n" if $verbose; my @in = docmd "($cmd) 2>&1"; return undef unless $#in >= 1; my %n; for (@in) { sub mang { my $n = shift; my $k = shift; return $n->{$k} ? sprintf("$k.%04x", int(rand(65535))) : $k; }; m/\s*([^:\t]+)\t*:\s*(.*)\s*/ && do { $n{mang(\%n, $1)} = $2; next; }; m/\s*([^=\t]+)\t*=\s*(.*)\s*/ && do { $n{mang(\%n, $1)} = $2; next; }; } return \%n; } sub docmd { my $cmd = shift; print "+ $cmd\n" if $verbose; my @cmd_output = `$cmd`; if ($verbose) { for (@cmd_output) { print "[$cmd] ", $_; } } return $cmd_output[0] if $#cmd_output == 0; return @cmd_output; } # default via 10.131.132.1 dev eth0 # 10.131.132.0/24 dev eth0 proto kernel scope link src 10.131.132.12 # 169.254.0.0/16 dev eth0 scope link metric 1000 # 172.20.0.9 dev ppp1 proto kernel scope link src 172.20.0.10 # 172.20.0.11 dev ppp0 proto kernel scope link src 172.20.0.12 # 192.168.1.0/24 via 192.168.3.5 dev tun0 # 192.168.3.1 via 192.168.3.5 dev tun0 # 192.168.3.5 dev tun0 proto kernel scope link src 192.168.3.6 # Station 00:15:ff:01:61:ef (on wlan0) # inactive time: 40 ms # rx bytes: 7839565 # rx packets: 58705 # tx bytes: 2931996 # tx packets: 11773 # tx retries: 5080 # tx failed: 212 # signal: -62 dBm # signal avg: -61 dBm # tx bitrate: 52.0 MBit/s MCS 5 # authorized: yes # authenticated: yes # preamble: long # WMM/WME: yes # MFP: no # TDLS peer: no # BSS 00:15:ff:01:61:ef (on wlan0) -- associated # TSF: 282177173 usec (0d, 00:04:42) # freq: 2417 # beacon interval: 100 # capability: ESS Privacy ShortSlotTime (0x0411) # signal: -64.00 dBm # last seen: 2741872 ms ago # Information elements from Probe Response frame: # SSID: squint # Supported rates: 1.0* 2.0* 5.5* 11.0* 18.0 24.0 36.0 54.0 # DS Parameter set: channel 2 # ERP: # RSN: * Version: 1 # * Group cipher: CCMP # * Pairwise ciphers: CCMP # * Authentication suites: PSK # * Capabilities: 16-PTKSA-RC (0x000c) # Extended supported rates: 6.0 9.0 12.0 48.0 # HT capabilities: # Capabilities: 0x182c # HT20 # SM Power Save disabled # RX HT20 SGI # No RX STBC # Max AMSDU length: 7935 bytes # DSSS/CCK HT40 # Maximum RX AMPDU length 65535 bytes (exponent: 0x003) # Minimum RX AMPDU time spacing: 8 usec (0x06) # HT RX MCS rate indexes supported: 0-7 # HT TX MCS rate indexes are undefined # HT operation: # * primary channel: 2 # * secondary channel offset: no secondary # * STA channel width: 20 MHz # * RIFS: 1 # * HT protection: no # * non-GF present: 0 # * OBSS non-GF present: 0 # * dual beacon: 0 # * dual CTS protection: 0 # * STBC beacon: 0 # * L-SIG TXOP Prot: 0 # * PCO active: 0 # * PCO phase: 0 # WMM: * Parameter version 1 # * u-APSD # * BE: CW 15-1023, AIFSN 3 # * BK: CW 15-1023, AIFSN 7 # * VI: CW 7-15, AIFSN 2, TXOP 3008 usec # * VO: CW 3-7, AIFSN 2, TXOP 1504 usec ################################################ # tunnels ################################################ if (-X "/bin/netstat") { my %procs; my %lports; for (docmd "/bin/netstat -pan 2>&1") { chomp; m{(\S+)\s+\d+\s+\d+\s+(\S+):(\d+)\s+(\S+):(\S+)\s+(\S+)\s+(\d+)/(\S+).*$} && do { my ($proto, $local, $lport, $remote, $rport, $state, $pid, $prog) = ($1, $2, $3, $4, $5, $6, $7, $8); next if $proto eq "tcp6" && $state eq "LISTEN"; $procs{$pid} = {} unless $procs{$pid}; my $p = $procs{$pid}; $p->{prog} = $prog; if ($state eq "LISTEN") { $p->{listening} = [] unless $p->{listening}; push(@{$p->{listening}}, $lport); } elsif ($state eq "ESTABLISHED") { $lports{$lport} = $prog if $local eq "127.0.0.1" or $local eq "::1"; $p->{inuse}->{$lport} = [] unless $p->{inuse}->{$lport}; push(@{$p->{inuse}->{$lport}}, $local eq "127.0.0.1" || $local eq "::1" ? "SELF:$rport" : $remote); } next; }; } while (my ($pid, $p) = each %procs) { while (my ($lport, $lp) = each %{$p->{inuse}}) { for (my $i = 0; $i < $#{$lp} + 1; $i++) { if ($lp->[$i] =~ m/SELF:(\d+)/) { $lp->[$i] = $lports{$1}; } } } } my $already = 0; while (my ($pid, $p) = each %procs) { if ($p->{listening} && $p->{inuse} && $p->{inuse}->{22}) { for my $lport (@{$p->{listening}}) { print "TUNNELS\n" unless $already++; printf(" %-10d %-31s %s\n", $lport, $p->{inuse}->{22}->[0], $p->{inuse}->{$lport} ? join(", ", @{$p->{inuse}->{$lport}}) : ""); } } } # print "LPORTS ", Dumper(\%lports); # print "PROCS ", Dumper(\%procs); } # Active Internet connections (servers and established) # Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name # tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 31234/cupsd # tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 16184/sshd: root@no # tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 30803/65 # tcp 0 0 127.0.0.1:6013 0.0.0.0:* LISTEN 8440/3 # tcp 0 0 0.0.0.0:25903 0.0.0.0:* LISTEN 16184/sshd: root@no # tcp 0 0 10.0.3.1:53 0.0.0.0:* LISTEN 30159/dnsmasq # tcp 0 0 0.0.0.0:20022 0.0.0.0:* LISTEN 16184/sshd: root@no # tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 21891/sshd # tcp 0 0 10.131.132.12:47297 10.131.132.11:22 ESTABLISHED 13946/slogin # tcp 0 0 10.131.132.12:22 10.22.30.114:35187 ESTABLISHED 15486/sshd: root@no # tcp 0 0 10.131.132.12:49842 10.131.132.22:22 ESTABLISHED 13940/slogin # tcp 0 0 10.131.132.12:59728 10.131.132.11:22 ESTABLISHED 3212/slogin # tcp 0 0 10.131.132.12:33390 10.131.132.13:22 ESTABLISHED 3180/slogin # tcp 0 0 10.131.132.12:49843 10.131.132.22:22 ESTABLISHED 13941/slogin # tcp 0 0 10.131.132.12:47298 10.131.132.11:22 ESTABLISHED 13947/slogin # tcp 0 0 10.131.132.12:47304 10.131.132.11:22 ESTABLISHED 13953/slogin # tcp 0 0 10.131.132.12:47307 10.131.132.11:22 ESTABLISHED 13962/slogin # tcp 0 0 10.131.132.12:47289 10.131.132.11:22 ESTABLISHED 13938/slogin # tcp 0 0 10.131.132.12:47302 10.131.132.11:22 ESTABLISHED 13951/slogin # tcp 0 0 10.131.132.12:59929 10.131.132.11:22 ESTABLISHED 4929/slogin # tcp 0 0 10.131.132.12:22 10.22.30.110:43448 ESTABLISHED 8343/sshd: root@not # tcp 0 0 10.131.132.12:47303 10.131.132.11:22 ESTABLISHED 13952/slogin # tcp 0 0 10.131.132.12:47301 10.131.132.11:22 ESTABLISHED 13949/slogin # tcp 0 0 10.131.132.12:22 10.22.30.114:58928 ESTABLISHED 30803/65 # tcp 0 0 10.131.132.12:47300 10.131.132.11:22 ESTABLISHED 13950/slogin # tcp 0 0 10.131.132.12:50194 10.131.132.55:22 ESTABLISHED 13942/slogin # tcp 0 0 10.131.132.12:47290 10.131.132.11:22 ESTABLISHED 13939/slogin # tcp 0 0 10.131.132.12:47309 10.131.132.11:22 ESTABLISHED 13969/slogin # tcp 0 0 10.131.132.12:22 10.22.30.114:34629 ESTABLISHED 8440/3 # tcp 0 0 127.0.0.1:20022 10.131.132.12:52493 ESTABLISHED 16184/sshd: root@no # tcp 0 0 10.131.132.12:50195 10.131.132.55:22 ESTABLISHED 13943/slogin # tcp 0 0 127.0.0.1:52493 127.0.0.1:20022 ESTABLISHED 3218/slogin # tcp 0 0 10.131.132.12:33392 10.131.132.13:22 ESTABLISHED 3179/slogin # tcp 0 0 10.131.132.12:47296 10.131.132.11:22 ESTABLISHED 13945/slogin # tcp 0 0 10.131.132.12:59005 10.131.132.21:22 ESTABLISHED 3184/slogin # tcp 0 0 10.131.132.12:47306 10.131.132.11:22 ESTABLISHED 13958/slogin # tcp 0 0 192.168.3.6:59929 192.168.1.9:22 TIME_WAIT - # tcp 0 0 10.131.132.12:53413 74.125.225.174:443 ESTABLISHED 23205/ # tcp 0 0 10.131.132.12:50196 10.131.132.55:22 ESTABLISHED 13944/slogin # tcp 0 0 10.131.132.12:59726 10.131.132.11:22 ESTABLISHED 3205/slogin # tcp 0 0 10.131.132.12:22 10.22.30.114:35195 ESTABLISHED 16184/sshd: root@no # tcp 0 0 10.131.132.12:38779 173.194.46.4:443 ESTABLISHED 23205/ # tcp 0 0 10.131.132.12:47305 10.131.132.11:22 ESTABLISHED 13954/slogin # tcp 0 0 10.131.132.12:47299 10.131.132.11:22 ESTABLISHED 13948/slogin # tcp 0 0 10.131.132.12:47308 10.131.132.11:22 ESTABLISHED 13964/slogin # tcp 0 0 10.131.132.12:25903 192.168.1.9:34342 ESTABLISHED 16184/sshd: root@no # tcp 0 0 10.131.132.12:44624 10.131.132.14:22 ESTABLISHED 3181/slogin # tcp 0 0 10.131.132.12:20022 192.168.1.9:44654 ESTABLISHED 16184/sshd: root@no # tcp 0 0 10.131.132.12:59725 10.131.132.11:22 ESTABLISHED 3202/slogin # tcp 0 0 10.131.132.12:59007 10.131.132.21:22 ESTABLISHED 3185/slogin # tcp6 0 0 ::1:631 :::* LISTEN 31234/cupsd # tcp6 0 0 ::1:6010 :::* LISTEN 16184/sshd: root@no # tcp6 0 0 ::1:6011 :::* LISTEN 30803/65 # tcp6 0 0 ::1:6013 :::* LISTEN 8440/3 # tcp6 0 0 :::25903 :::* LISTEN 16184/sshd: root@no # tcp6 0 0 fe80::94df:22ff:fe87:53 :::* LISTEN 30159/dnsmasq # tcp6 0 0 :::20022 :::* LISTEN 16184/sshd: root@no # tcp6 0 0 :::22 :::* LISTEN 21891/sshd # tcp6 0 0 ::1:59907 ::1:6010 ESTABLISHED 16352/x2x # tcp6 0 0 ::1:6010 ::1:59907 ESTABLISHED 16184/sshd: root@no # tcp6 1 0 ::1:60133 ::1:631 CLOSE_WAIT 1028/cups-browsed # udp 0 0 10.131.132.12:60001 0.0.0.0:* 1696/mosh-server # udp 0 0 10.131.132.12:60002 0.0.0.0:* 900/mosh-server # udp 0 0 10.131.132.12:60003 0.0.0.0:* 1239/mosh-server # udp 0 0 0.0.0.0:631 0.0.0.0:* 1028/cups-browsed # udp 0 0 0.0.0.0:56112 0.0.0.0:* 16656/mosh-client e # udp 0 0 0.0.0.0:41898 0.0.0.0:* 5894/mosh-client e # udp 0 0 0.0.0.0:48315 0.0.0.0:* 13834/openvpn # udp 0 0 0.0.0.0:5353 0.0.0.0:* 23205/ # udp 0 0 0.0.0.0:5353 0.0.0.0:* 857/avahi-daemon: r # udp 0 0 0.0.0.0:38841 0.0.0.0:* 857/avahi-daemon: r # udp 0 0 10.0.3.1:53 0.0.0.0:* 30159/dnsmasq # udp 0 0 0.0.0.0:67 0.0.0.0:* 30159/dnsmasq # udp6 0 0 :::5353 :::* 857/avahi-daemon: r # udp6 0 0 :::38136 :::* 857/avahi-daemon: r # udp6 0 0 fe80::94df:22ff:fe87:53 :::* 30159/dnsmasq # Active UNIX domain sockets (servers and established) # Proto RefCnt Flags Type State I-Node PID/Program name Path # unix 2 [ ACC ] STREAM LISTENING 12803 857/avahi-daemon: r /var/run/avahi-daemon/socket # unix 2 [ ACC ] STREAM LISTENING 13533 1053/X /tmp/.X11-unix/X0 ################################################ # command line processing ################################################ sub do_command { my @args = @_; for (@args) { m/^def/ && do { my $gw = shift @args; die usage() unless $gw; dos("/sbin/ip route delete default"); dos("/sbin/ip route add default via $gw"); exit; }; m/^grok/ && do { my $sample = shift @args; die usage() unless $sample; printf("GROK %s\n", Dumper(grok($sample))); exit; }; die usage(); } } sub dos { my $cmd = shift; print "+ $cmd\n"; system($cmd); } sub usage { return "usage: $0 [default ]\n"; }