如何在perl脚本中获取IP地址,脚本该怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:39:11

方法很多。
可以从ifconfig命令的结果中取对应字符串:

open (IN, "/sbin/ifconfig |");
while (<IN>) {
if ( /^\s*inet addr:([\d\.]*)\s*Bcast:([\d\.]*)\s*Mask:([\d\.]*)/ ) {
$host_ip = $1;
last ;
}
}
close(IN);

$host_ip里的就是结果。

知道也不想说

随便注册一个号就来了