LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 996|回复: 5

获取 ip 地址![已解决]

[复制链接]
发表于 2004-1-20 14:44:57 | 显示全部楼层 |阅读模式
用 shell 实现

./ifconfig
ppp0      Link encapoint-to-Point Protocol
          inet addr:61.190.82.35  P-t-P:24.24.24.24  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
          RX packets:3634 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3511 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:2586031 (2.4 Mb)  TX bytes:678348 (662.4 Kb)

//
想获得 61.190.82.35
我使用 ./ifconfig | grep '61.190' | colrm 1 14 | colrm xx xx

问题是这个可以地址可以改变为:
61.190.xxx.xxx

colrm 就无法处理了!
//
不知道有没有其他方法?
发表于 2004-1-20 15:21:52 | 显示全部楼层
这样可以获得IP地址:
ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"

要是不明白请楼主一步步的试!!
发表于 2004-1-21 15:49:43 | 显示全部楼层
/sbin/ifconfig ppp0 | sed -ne 's/\(.*\)addr:\([[:digit:].]*\)\(.*\)/\2/p'
发表于 2004-1-22 21:31:08 | 显示全部楼层
  1. /sbin/ip addr|awk '/ppp0$/{print $2}'
复制代码
发表于 2004-1-28 11:38:02 | 显示全部楼层
#ifconfig ppp0 |grep addr |awk '{print $2;}' |sed s/addr://
发表于 2004-1-28 14:32:50 | 显示全部楼层
ifconfig ppp0 |grep ^[[:space:]]*inet\ addr |sed s/^[[:space:]]*inet\ addr\:// |sed s/[[:space:]].*$//
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表