嘉定都市网

标题: [推荐]Linux的ipconfig [打印本页]

作者: boring    时间: 2004-2-8 08:39
标题: [推荐]Linux的ipconfig
#!/usr/bin/perl
#
# \'ipconfig\' like output - written as an experiment
# Jan 07, 2003 by Bevan Bennett (bevan fulcrummicro com)
#


open(IFINFO,\'/sbin/ifconfig|\') || die \"couldn\'t run ifconfig: $!\\n\";

%interfaces = ();
$current = \"\";
$hostname = $ENV{\"HOSTNAME\"};


while (<IFINFO>) {
  /^(\\S+)\\s+Link encap:Ethernet\\s+HWaddr\\s+(\\S+)/ && do {
    $interfaces{$1}{\"hwaddr\"} = $2;
    $current = $1;
    next;
  };
  /^lo/ && do {
    $current = \"\";
    next;
  };
  next if (!$current);
  /inet addr[\\d\\.]+)/ && do {$interfaces{$current}{\"ipaddr\"} = $1;};
  /Mask[\\d\\.]+)/ && do {$interfaces{$current}{\"mask\"} = $1;};
}
close(IFINFO);


open (DNSINFO,\'/etc/resolv.conf\') || die \"Can\'t open /etc/resolv.conf: $!\\n\";
while (<DNSINFO>) {
/^domain (\\S+)/ && do { $dnsdomain = $1; };
/^search (.+)/ && do { @dnssearch = split / /,$1; };
/^nameserver (\\S+)/ && do { push @dnssrv,$1; };
}
close (DNSINFO);

open (ROUTEINFO,\'netstat -rn|\') || die \"Can\'t run netstat: $!\\n\";
while (<ROUTEINFO>) {
  /0\\.0\\.0\\.0\\s+(\\S+)\\s+\\S+\\s+UG\\s+\\d+\\s+\\d+\\s+\\d+\\s+(\\S+)/ && do {
    $gateway = $1;
    $gateint = $2;
  };
}
close (ROUTEINFO);



print \"Fedora Core IP Configuration\\n\\n\";
print \" Host Name . . . . . . . . . . . . . : \" . $hostname . \"\\n\";
print \" Primary DNS Suffix. . . . . . . . . : \" . $dnsdomain . \"\\n\";
print \" DNS Suffix Search List. . . . . . . : \" . shift(@dnssearch) . \"\\n\";
while (@dnssearch) {
print \" \" . shift(@dnssearch) . \"\\n\";
}
print \" DNS Servers . . . . . . . . . . . . : \" . shift(@dnssrv) . \"\\n\";
while (@dnssrv) {
print \" \" . shift(@dnssrv) . \"\\n\";
}
print \" Default Gateway . . . . . . . . . . : \" . $gateway . \" (\"
. $gateint . \")\\n\";
print \"\\n\";

foreach $if (keys(%interfaces)) {
print \"Ethernet adapter Local Area Connection $if:\\n\\n\";
print \" Physical Address. . . . . . . . . . : \" . $interfaces{$if}{\"hwaddr\"} . \"\\n\";
print \" IP Address. . . . . . . . . . . . . : \" . $interfaces{$if}{\"ipaddr\"} . \"\\n\";
print \" Subnet Mask . . . . . . . . . . . . : \" . $interfaces{$if}{\"mask\"} . \"\\n\";
print \"\\n\";
}
       

此贴由 boring 在 2004-04-20 20:53:43 最后编辑
作者: ziyinghe    时间: 2004-2-8 09:44
看不懂
作者: 太极    时间: 2004-2-8 11:10
把表情转换关了
作者: [二孬]    时间: 2004-2-8 11:30
perl得
有没有c的??
作者: terry    时间: 2004-4-21 10:36
ifconfig不就可以了
作者: [二孬]    时间: 2004-4-21 13:34


用竟java也能实现查看本地IP地址
作者: terry    时间: 2004-4-21 18:58
原文由 [二孬] 在 2004-04-21 13:34:32  发表


用竟java也能实现查看本地IP地址


难道你以为java是豆腐
作者: [二孬]    时间: 2004-4-21 19:17

当然不是豆腐啊~~最近在做东西,老师逼着交一个基于网路的系统状况监视,唉,做吧~~~
作者: terry    时间: 2004-4-21 22:40
有空多去sourceforge逛逛,运气好或者熟悉的话能节省你60%的时间。
作者: [二孬]    时间: 2004-4-22 16:31

source我常去,,东西也常找,

不过这个,老师规定,不许使用第三方的东西~~~

网路部分OK了,剩下的是系统状况报告和基于Applet的浏览界面了
作者: flytosea    时间: 2004-4-23 15:54
一群高手,我真是景仰你们!
作者: [二孬]    时间: 2004-4-23 17:01
我是大菜鸟
作者: terry    时间: 2004-4-23 18:43
我最多是只菜鸡,哈哈哈。




欢迎光临 嘉定都市网 (http://www.jiading.com.cn/) Powered by Discuz! X3.1