如果连续 ping 失败则启动跟踪路由的脚本,输出到日志
我想连续 ping 我的家庭公共 IP 地址,如果 ping 失败,则自动执行跟踪路由以查看失败的位置。
我一直在尝试遵循此处发表的评论:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/efc97c66-60a6-4fd7-8be4-4b454d040ce5
Windows 兼容更好,bat 或 vbs会是最好的。
从互联网上的任何地方我都会失去与家庭网络的连接。在工作中,我开始执行 ping 操作,当它失败时,我执行了跟踪路由,但在到达我的 IP 之前它就失败了。
我需要一个日志文件来证明它不是我的调制解调器、路由器或计算机。
I want to continuously ping my home public IP address, and if the ping fails automatically do a traceroute to see where it's failing.
I've been trying to follow the comments made here:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/efc97c66-60a6-4fd7-8be4-4b454d040ce5
Windows compatible would be preferable, bat or vbs would be best.
From anywhere on the internet I will lose my connection to my home network. From work I have started a ping and when it drops I've done a traceroute and it fails before it gets to my IP.
I need a log file to prove that it is not my modem, or router, or computer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果其他人需要这个,这就是我最终选择的。本质上,“Ping -n 127.0.0.1>Nul”是添加一个 5 秒计数器,以便它每 5 秒 ping 一次目的地,5 可以更改为任何需要的值。
Windows 7 存在这样的问题,即 ping 可能会出现类似“来自 192.168.1.5 的回复:目标主机无法访问”的结果。因此,它不会出错,而是会得到自身的回复,而不是错误级别 1。
我选择使用 "%SystemRoot%\system32\ping.exe -n 1 %Address% | %SystemRoot%\system32\find.exe "TTL=" > NUL 查找 TTL 的无结果,而不是查找错误级别 1 “
无论如何,我确信这里的其他答案非常相似并且可能有效,所以我将它们排名,但将其标记为答案。
谢谢大家!
This is what I ended up going with, if anyone else ever needs this. Essentially the "Ping -n 127.0.0.1>Nul" is to add a 5 second counter so that it only pinged the destination every 5 seconds, 5 can be changed to whatever value is needed.
Windows 7 has this problem where a ping may result with something like "reply from 192.168.1.5: Destination host unreachable". So instead of erroring out it gets a reply from itself and not the error level 1.
Instead of looking for Error Level 1 I choose to look for no result for TTL with "%SystemRoot%\system32\ping.exe -n 1 %Address% | %SystemRoot%\system32\find.exe "TTL=" > NUL"
Anyway, I'm sure the other answers here were very similar and may have worked, so I am ranking them up, but marking this as the answer.
Thanks all!
您可以制作一个简单的批处理文件来尝试 ping,如果失败则进行tracert,例如:
这里有很大的改进空间。
然后创建一个计划任务,每五分钟运行一次或任何适合您的任务。
或者,您可以包含一个带有“睡眠”的循环。 在批处理文件中睡觉有一个穷人的睡眠,它使用:
You could make a simple batch file that tries a ping and if it fails does a tracert, eg:
There's plenty of scope for refinement here.
Then create a scheduled task that runs it every five minutes or whatever suits you.
Alternatively you could include a loop with a 'sleep' in it. There's a poor man's sleep at Sleeping in a batch file that uses:
基本上,这表示执行
ping
,如果它找到包含单词Request
实例的行(仅当您无法 ping 地址时才会出现),则执行 Tracert 。PING
中的-n
和-w
开关告诉它只跳转一次,并在没有得到响应的 1 秒后超时。如果您正在 ping 本地主机,这完全没问题。第二个FOR
语句是有一个停止点。将1400
更改为您希望脚本停止的时间(当然是军事时间)。Basically, this states do
ping
, if it finds a line that has an instance of the wordRequest
(which only appears if you can't ping the address) perform a tracert. The-n
and-w
switches inPING
tell it to jump only once and timeout after 1 second of not getting a response. This is perfectly fine if you are pinging your localhost. The secondFOR
statement is to have a stopping point. Change the1400
to a time you wish for the script to stop (in military time of course).我一直在寻找同样的东西来调查为什么 VPN 在有线连接上不断掉线,使用了上面的批处理文件建议之一,这很棒。
还发现了一个不错的小 Java 应用程序,它在这里为您打包
互联网连接监视器
简单易用,功能强大:- )
I have just been looking for the same thing to investigate why a VPN keeps dropping on a wired connection, used one of the batch file suggestions above which was great.
Also found a nice little Java App which packages it for you here
Internet Connectivity Monitor
Simple to use and does the job :-)