刘添悟 發表於 2020-5-8 09:53:05

电脑ping命令的结果怎么输出到txt文本?

<p>网络排错中最常用的是ping命令,为了将结果把保存到txt文档中,便于反复查看,方法如下:</p>
<p>1、<strong>win+R</strong>组合打开运行,或者从搜索栏搜索&ldquo;<strong>运行</strong>&rdquo;,输入<strong>cmd打开doc窗口</strong>,回车。</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351019.jpg" /></p>
<p>2、比如常<strong>ping192.168.0.1,输出到d盘ping.txt文件中。</strong></p>
<p>输入命令:<span style="color: #ff0000"><strong>ping 192.168.0.1 -t &gt;&gt;d:/ping.txt</strong></span>,回车</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351020.jpg" /></p>
<p>3、打开d盘,此时显示ping.txt文件夹</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351121.jpg" /></p>
<p>4、打开ping.txt文件夹,即可看到ping测试的结果。</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351122.jpg" /></p>
<p><strong>补充扩展: </strong></p>
<p><span style="color: #ff0000"><strong><span id="1588902413066S" style="display: none">&nbsp;</span>ping命令加入时间戳并写入文本&nbsp; </strong></span></p>
<p><strong>【需求背景】</strong></p>
<p>判断网络质量咋样,我们第一时间想到的就是ping,那么有没有一种方法可以在ping的时候加入时间戳并把ping记录写入到文本里面,当然是有的啦!啥意思图,看下图啦:</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351123.jpg" /></p>
<p><strong>【具体操作】</strong></p>
<p>1.将以下内容复制粘贴到文本文档,并改格式为vbs(或者后台回复ping即可下载该脚本,脚本出处不详,感谢大神!)</p>
<div class="jb51code">
<pre class="brush:plain;">
Dim args, flag, unsuccOut
args=&quot;&quot;
otherout=&quot;&quot;
flag=0
If W.Arguments.count = 0 Then
W.Echo &quot;Usage: c tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]&quot;
W.Echo &quot; [-s count] [[-j host-list] | [-k host-list]]&quot;
W.Echo &quot; [-r count] [-w timeout] destination-list&quot;
w.quit
End if
For i=0 to W.Arguments.count - 1
args=args &amp; &quot; &quot; &amp; W.Arguments(i)
Next
Set shell = W.CreateObject(&quot;W.Shell&quot;)
Set re=New RegExp
re.Pattern=&quot;^Reply|^Request|^来自|^请求&quot;
Set myping=shell.Exec(&quot;ping&quot; &amp; args)
while Not myping.StdOut.AtEndOfStream
strLine=myping.StdOut.ReadLine()
'W.Echo &quot;原数据&quot; &amp; chr(9) &amp; strLine
r=re.Test(strLine)
If r Then
W.Echo date &amp; &quot; &quot;&amp; time &amp; chr(9) &amp; strLine
flag=1
Else
unsuccOut=unsuccOut &amp; strLine
End if
Wend
if flag = 0 then
W.Echo unsuccOut
end if</pre>
</div>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351124.jpg" /></p>
<p><strong>【测试与验证】</strong></p>
<p>记录脚本位置,执行如下命令:</p>
<p><span style="color: #ff0000"><strong>CD:\ping.vbs www.baidu.com -t -l 1024 &gt;&gt; D:\baidu.txt</strong></span></p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351125.jpg" /></p>
<p>看记录文件自己生成啦!</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351126.jpg" /></p>
<p>效果如下图:</p>
<p align="center"><img alt="" src="https://img.jbzj.com/file_images/article/202005/2020050809351127.jpg" /></p>
<p>以上就是ping输出到文本的技巧,希望大家喜欢,请继续关注琼殿技术社区。</p>
<p><strong>相关推荐:</strong></p>
<p>电脑Ping IP时出现request time out怎么办?</p>
頁: [1]
查看完整版本: 电脑ping命令的结果怎么输出到txt文本?