} else {
1 j! \& O1 p8 W, q @ip = $tmp =~ /\w{2}/g;2 O0 v# P ~3 c" [
foreach my $index (0..3){3 x: y# u% S% }4 u0 ^
$ip[$index] = hex($ip[$index]);
$ J" ^9 E7 j$ T) b8 `* n }
$ Y. b5 s' r; D* A/ R $int = sprintf("%d.%d.%d.%d", hex($ip[3]), hex($ip[2]), hex($ip[1]), hex($ip[0]));5 [0 h3 A6 a2 ]
}
, d% r( K; d2 l. d& T+ F& P return $int;, N$ w% B; r L5 y8 ?( @
}
5 W# k. d& h# v4 H% }* e. @% s+ ` ############################## {1 D# {3 ^8 D5 f- M; z+ F- b
# Show Kernel route table
* p ?& U# S9 b z ############################
. h) A' o' V, ]: H7 t8 A# e. }9 h sub route_info($) {
9 Q5 e9 y! j( H my $routefile = shift;( P1 ?# z- {6 e1 o8 l/ e
open(ROUTE, $routefile) or die ("Can't open route file!\n");" @, ]; x/ O5 I* K. L) n
my $header = "Iface Destination Gateway Flags Genmask\n";
; H$ V% {+ Q# m/ f printf("%s", $header);- f1 Z- h/ g! `5 p! @2 ~
my $format = "%-5s %-15s %-15s %-5s %-15s\n";
9 P9 \) Y: x' a4 X( b: A! x, t while() {
# T8 s3 p5 n' m: k4 C: l8 v& K. g next if /Iface/;
9 w, {# e+ i8 U my @line = split; e# x9 E" n& I5 N: l" R" h- n9 l
my ($iface, $dest, $gw, $flags, $mask ) = ($line[0], &hextoint($line[1]), &hextoint($line[2]), hex($line[3]), &hextoint($line[7]));
, D7 T, m3 z6 E% i: j/ n c printf($format, $iface, $dest, $gw, $routeType[$flags], $mask );$ Z0 o8 l2 v; u9 T
}
# [2 J1 X3 {2 s I close(ROUTE);
' }7 @3 J/ `" t2 {, ` }7 t6 L) r% n( A! J. e
#############################' j! ]0 y4 d% z6 _) b
# Show help information8 G5 |6 ]$ S# d& Z, ^
############################* x. `" B; T# P2 ~: u l! {7 Y: r
sub usage {) \% H% z$ z. J! y3 l. R
printf("%s\n\n%-30s\n%-30s\n%-30s\n%-30s\n%-30s\n%-30s\n",. u M" K- l0 n: ~" d, l* c
"netstat written in Perl by FinalBSD.Copyright(c) 2008.",0 g5 j* T5 h* D+ D4 ^
"-n Show numeric ip and port address.",- j3 c9 |; D- X6 D# H1 O
"-r Display the kernel routing table."," k, z" d0 J0 s
"-a Show both listening and non-listening socktes.",
; T" o. `, d) Z2 H/ y1 v( v "-t Show only TCP statistics.",. X" A0 M$ H6 b3 T% B7 `
"-l Show only listening sockets.",5 \) }: ]- X1 a* p, e0 y5 d
"-h Show help.",
( R) v$ C' k- e" O7 F );
, e6 }9 K& B7 M exit;& l1 A1 `2 H; J$ i& a
} |