📄 slackware-linux-lib.pl
字号:
# redhat-linux-lib.pl# Networking functions for redhat linux# active_interfaces()# Returns a list of currently ifconfig'd interfacessub active_interfaces{local(@rv, @lines, $l);open(IFC, "ifconfig -a |");while(<IFC>) { s/\r|\n//g; if (/^\S+/) { push(@lines, $_); } else { $lines[$#lines] .= $_; } }close(IFC);foreach $l (@lines) { local %ifc; $l =~ /^([^:\s]+)/; $ifc{'name'} = $1; $l =~ /^(\S+)/; $ifc{'fullname'} = $1; if ($l =~ /^(\S+):(\d+)/) { $ifc{'virtual'} = $2; } if ($l =~ /inet addr:(\S+)/) { $ifc{'address'} = $1; } else { next; } if ($l =~ /Mask:(\S+)/) { $ifc{'netmask'} = $1; } if ($l =~ /Bcast:(\S+)/) { $ifc{'broadcast'} = $1; } if ($l =~ /HWaddr (\S+)/) { $ifc{'ether'} = $1; } if ($l =~ /MTU:(\d+)/) { $ifc{'mtu'} = $1; } $ifc{'up'}++ if ($l =~ /\sUP\s/); $ifc{'edit'} = ($ifc{'name'} !~ /^ppp/); $ifc{'index'} = scalar(@rv); push(@rv, \%ifc); }return @rv;}# activate_interface(&details)# Create or modify an interfacesub activate_interface{local $a = $_[0];local $cmd = "ifconfig $a->{'name'}";if ($a->{'virtual'} ne "") { $cmd .= ":$a->{'virtual'}"; }$cmd .= " $a->{'address'}";if ($a->{'netmask'}) { $cmd .= " netmask $a->{'netmask'}"; }if ($a->{'broadcast'}) { $cmd .= " broadcast $a->{'broadcast'}"; }if ($a->{'mtu'}) { $cmd .= " mtu $a->{'mtu'}"; }if ($a->{'up'}) { $cmd .= " up"; }else { $cmd .= " down"; }local $out = `$cmd 2>&1`;if ($?) { &error($out); }if ($a->{'ether'}) { $out = `ifconfig $a->{'name'} hw ether $a->{'ether'} 2>&1`; if ($?) { &error($out); } }}# deactivate_interface(&details)# Shutdown some active interfacesub deactivate_interface{local $cmd = "ifconfig $a->{'name'}";if ($a->{'virtual'} ne "") { $cmd .= ":$a->{'virtual'}"; }$cmd .= " down";local $out = `$cmd 2>&1`;if ($?) { &error($out); }}# iface_type(name)# Returns a human-readable interface type namesub iface_type{return "PPP" if ($_[0] =~ /^ppp/);return "SLIP" if ($_[0] =~ /^sl/);return "PLIP" if ($_[0] =~ /^plip/);return "Ethernet" if ($_[0] =~ /^eth/);return "Arcnet" if ($_[0] =~ /^arc/);return "Token Ring" if ($_[0] =~ /^tr/);return "Pocket/ATP" if ($_[0] =~ /^atp/);return "Loopback" if ($_[0] =~ /^lo/);return "Unknown";}# iface_hardware(name)# Does some interface have an editable hardware addresssub iface_hardware{return $_[0] =~ /^eth/;}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -