免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2549 | 回复: 9
打印 上一主题 下一主题

ping 的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-03 13:52 |只看该作者 |倒序浏览
5可用积分
PING 192.168.4.1 (192.168.4.1) 56(84) bytes of data.

64 bytes from 192.168.4.1: icmp_seq=1 ttl=128 time=0.284 ms



--- 192.168.4.1 ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 0.284/0.284/0.284/0.000 ms

PING 192.168.5.1 (192.168.5.1) 56(84) bytes of data.

From 192.168.4.202 icmp_seq=1 Destination Host Unreachable



--- 192.168.5.1 ping statistics ---

1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms



PING 192.168.4.2 (192.168.4.2) 56(84) bytes of data.

64 bytes from 192.168.4.2: icmp_seq=1 ttl=255 time=0.980 ms



--- 192.168.4.2 ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 0.980/0.980/0.980/0.000 ms

PING 192.168.5.2 (192.168.5.2) 56(84) bytes of data.

From 192.168.4.202 icmp_seq=1 Destination Host Unreachable



--- 192.168.5.2 ping statistics ---

1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms



PING 192.168.4.3 (192.168.4.3) 56(84) bytes of data.

64 bytes from 192.168.4.3: icmp_seq=1 ttl=64 time=1.27 ms

怎么把上面的数据ping通的ip地址给挑选出来?
或者有什么更好的方法把一个网段能ping通的主机给挑选出来?

最佳答案

查看完整内容

[root@Mylinux tmp]# awk '/PING/{ip=$2}/time=/{print ip}' file192.168.4.1192.168.4.2192.168.4.3[root@Mylinux tmp]# awk '/time=/{sub(//,"",$4);print $4}' file 192.168.4.1192.168.4.2192.168.4.3[ 本帖最后由 ywlscpl 于 2010-1-3 14:49 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2010-01-03 13:52 |只看该作者
[root@Mylinux tmp]# awk '/PING/{ip=$2}/time=/{print ip}' file
192.168.4.1
192.168.4.2
192.168.4.3

[root@Mylinux tmp]# awk '/time=/{sub(//,"",$4);print $4}' file  
192.168.4.1
192.168.4.2
192.168.4.3

[ 本帖最后由 ywlscpl 于 2010-1-3 14:49 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2010-01-03 14:04 |只看该作者

回复 #1 蓝血攻击者 的帖子

你把那些信息都在文件中存着没?还是想直接通过终端的输出找出来?

论坛徽章:
0
4 [报告]
发表于 2010-01-03 14:07 |只看该作者
PING 192.168.4.1 (192.168.4.1) 56(84) bytes of data.

64 bytes from 192.168.4.1: icmp_seq=1 ttl=128 time=0.284 ms

PING 192.168.4.2 (192.168.4.2) 56(84) bytes of data.

64 bytes from 192.168.4.2: icmp_seq=1 ttl=255 time=0.980 ms

PING 192.168.4.3 (192.168.4.3) 56(84) bytes of data.

64 bytes from 192.168.4.3: icmp_seq=1 ttl=64 time=1.27 ms
这些ip给显示出来!

论坛徽章:
0
5 [报告]
发表于 2010-01-03 14:09 |只看该作者
原帖由 luoxinfeng 于 2010-1-3 14:04 发表
你把那些信息都在文件中存着没?还是想直接通过终端的输出找出来?

文件有,把从文件里面给挑选出来!谢谢

论坛徽章:
0
6 [报告]
发表于 2010-01-03 14:29 |只看该作者

回复 #3 蓝血攻击者 的帖子

你先试试这个吧:

more  yourfile | grep 'ttl' | awk  ‘{print $4}’ | awk -F\(  '{print $2}' | awk -F\) '{print $1}' >ip.txt

其中yourfile 是你存放结果的文件

论坛徽章:
0
7 [报告]
发表于 2010-01-03 14:41 |只看该作者
  1. awk 'BEGIN{RS="PING";FS="\n"} NR>1{print"----------";printf $1"\n"$2$3"\n";print "----------"}' file
复制代码

格式不太好,希望能提供给你一点思路

论坛徽章:
0
8 [报告]
发表于 2010-01-03 14:48 |只看该作者

回复 #5 luoxinfeng 的帖子

more  yourfile | grep 'ttl' | awk  ‘{print $4}’  >file
这样子应该就好了把
后面是??

论坛徽章:
0
9 [报告]
发表于 2010-01-03 15:35 |只看该作者
谢谢各位了。。问题已经得到处理了~不好意思分有一点少。。还有各位的思路都很好。。。谢谢大家。。

论坛徽章:
0
10 [报告]
发表于 2010-01-04 11:21 |只看该作者
怎么解决的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP