Ping 总是成功,无法在 url 上使用 ping 轻松检查正常运行时间
我很沮丧,因为 OpenDNS 和其他服务(即:roadrunner)现在总是返回 ping,即使您输入任何无效的 url,即:lkjsdaflkjdsjf.com --- 我已经创建了供自己使用的软件,可以 ping 一个 url 来验证该网站是否已启动。 这不再有效。 有人对此有什么想法吗?
要求:
- 它应该与任何有效的网站一起工作,即使是我无法控制的网站
- 它应该能够从任何可以访问互联网的网络运行
我非常感谢听到其他人现在如何处理这个问题。 我想补充一点,我正在尝试在 c# 中使用 System.Net 来执行此操作,
非常感谢:-)
新添加:寻找一个可以在我的 Windows 计算机上购买和运行或在 c# 中编程的解决方案。 :-)
更新:
非常感谢大家的回答。 最终我通过这样做创建了一个解决方案:
- 创建一个简单的 Web 客户端,从 url 下载指定的页面(可能更改为仅标题或使用它来通知页面更改)
- 读取 xml 文件,该文件仅列出了完整的 url要检查的站点/页面
- 创建了一个 Windows 服务来托管解决方案,以便它可以恢复服务器重新启动。
- 出现错误时,电子邮件和短信将发送到定义的收件人列表
- 大多数值(间隔、smtp、收件人、发件人等)都在 .config 中定义,以便于更改
我将采纳您的一些建议来添加“功能”稍后,其中包括:
- 用于实时监控的AJAX页面。 我将使用 WCF 从 asp.net 页面连接到现有的 Windows 服务
- 仅下载标头(带有页面更改比较选项),
- 使可配置性更强(即:在通知之前失败时重试)
Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always returns a ping even if you type any invalid url ie: lkjsdaflkjdsjf.com --- I had created software for my own use that would ping a url to verify if the site was up or not. This no longer works. Does anyone have any ideas about this?
Requirements:
- It should work with any valid web site, even ones i dont control
- It should be able to run from any network that has internet access
I would greatly appreciate to hear how others now handle this. I would like to add, im attempting to do this using System.Net in c#
Thank you greatly :-)
New addition: Looking for a solution that i can either buy and run on my windows machine, or program in c#. :-)
Update:
Thank you all very much for your answers. Ultimately i ended up creating a solution by doing this:
- Creating a simple webclient that downloaed the specified page from the url (may change to just headers or use this to notify of page changes)
- Read in xml file that simply lists the full url to the site/pages to check
- Created a windows service to host the solution so it would recover server restarts.
- On error an email and text message is sent to defined list of recipients
- Most values (interval, smtp, to, from, etc) are defined in the .config for easy change
I will be taking some of your advice to add 'features' to this later, which includes:
- AJAX page for real-time monitoring. I will use WCF to connect to the existing windows service from the asp.net page
- Download Headers only (with option for page change comparison)
- make more configurable (ie: retries on failure before notification)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
Wget 是一个不错的选择。 它不仅会检查机器是否处于活动状态,还会检查 HTTP 服务器是否正在接受连接。
Wget is a nice alternative. It will check not only whether the machine is active, but also whether the HTTP server is accepting connections.
您可以创建一个简单的网页,其中包含网站的地址栏和一些使用 AJAX 访问网站的 javascript。 如果您在异步回调中收到除 200 之外的任何 HTTP 响应,则该网站无法正常工作。
这段代码取决于浏览器不是 IE,我还没有测试过它,但它应该给你一个非常好的主意。
You could create a simple web page with an address bar for the website and some javascript that uses AJAX to hit a site. If you get any HTTP response other than 200 on the async callback, the site isn't working.
This code depends on the browser not being IE and I haven't tested it, but it should give you a really good idea.
要查看服务是否已启动,您不仅应该执行 ping 操作,而且最好使用脚本来访问服务(例如网站)并返回有效响应。 我过去使用过 What's Up Gold,而不是自己编写。 我喜欢此类产品的所有功能。 例如当服务关闭时向我发送寻呼。
To see if a service is up, not only should you ping, but it's good to have scripts that will hit a service, such as a website, and get back a valid response. I've used What's Up Gold in the past, rather than write my own. I like all the features in products like that. such as sending me a page when a service is down.
根据记录,lkjsdaflkjdsjf.com 是一个主机名(目前尚未向任何人注册)。 ping 不适用于 URL,而 ping 则适用于主机名。 使用域名系统查找主机名。 当主机名未注册时,DNS 应该会失败。
问题是某些服务(显然是您的 ISP,当然还有 OpenDNS)不会使未注册的主机名的 DNS 请求失败。 相反,它们返回网络上主机的 IP 地址,该主机向任何 http 请求提供搜索页面。
您似乎想知道两件事:该名称是否真实(即,是否有使用该名称的主机注册到某个实际机器)? 那台机器运转正常吗?
如果您已经知道所讨论的名称是真实的(例如,您想知道 www.google.com 是否已启动),那么您可以使用 ping,因为您知道该名称将解析为真实地址(ISP 可以不会返回其注册名称的 IP),并且您只会测量该机器是否正在运行。
如果您不知道该名称是否真实,那么问题会更加困难,因为您的 ISP 正在向您的 DNS 请求返回虚假数据。 这里唯一的解决方案是找到一个不会在未解析的名称方面对您撒谎的 DNS 服务器。
我能想到的区分 ISP 的虚假记录和真实记录的唯一方法是进行反向查找< /a> 在您返回的 IP 上,查看该 IP 是否在您的 ISP 网络中。 这个技巧的问题在于,如果 ISP 没有该 IP 的反向 DNS 信息,您将不知道这是 ISP 还是只是某个没有正确配置 DNS 的傻瓜(我已经犯过很多次这样的错误)过去的时间)。
我确信还有其他技术,但 DNS 位于一切事物的底层这一事实使得解决这个问题变得困难。
For the record, lkjsdaflkjdsjf.com is a hostname (which at the moment is not registered to anyone). ping does not work with URLs, ping works with hostnames. hostnames are looked up using the Domain Name System. DNS is supposed to fail when hostnames are not registered.
The problem is that some services (apparently your ISP, and definitely OpenDNS) do NOT fail DNS requests for hostnames that aren't registered. Instead they return the IP address of a host on their network that presents a search page to any http request.
You appear to want to know two things: Is the name real (that is, is there a host with this name registered to some actual machine)? and Is that machine functioning?
If you already know that the name in question is real (for instance, you want to know if www.google.com is up), then you can use ping because you know that the name will resolve to a real address (the ISP can't return their IP for a registered name) and you'll only be measuring whether that machine is in operation.
If you don't know whether the name is real, then the problem is harder because your ISP is returning false data to your DNS request. The ONLY solution here is to find a DNS server that is not going to lie to you about unresolved names.
The only way I can think of to differentiate between your ISP's fake records and real ones is to do a reverse lookup on the IP you get back and see if that IP is in your ISP's network. The problem with this trick is that if the ISP doesn't have reverse DNS info for that IP, you won't know whether it's the ISP or just some knucklehead who didn't configure his DNS properly (I've made that mistake many times in the past).
I'm sure there are other techniques, but the fact that DNS lies underneath everything makes it hard to deal with this problem.
不直接知道 C# 中有任何现成的选项,尽管如果没有一些可用的选项,我会感到非常惊讶。
几年前我写过类似的东西,不再有代码,因为它属于其他人,但基本思想是使用 WebClient 访问域默认页面,并检查 http 状态代码 200。
您可以然后围绕此操作的成功或失败连接任何通知逻辑。
如果带宽是一个问题,您可以将其缩减为仅使用 HEAD 请求。
对于您控制的更复杂的站点,您可以连接一个运行状况监控页面,该页面在发送响应之前进行一些更深入的测试,例如数据库连接是否正常等。
通常,端口 80 上失效的计算机仍会响应ping,因此测试端口 80(或您感兴趣的任何其他端口)将是一种更可靠的方法。
Don't directly know of any off the shelf options in c#, although I'd be very suprised if there aren't a few available.
I wrote something similar a few years ago, don't have the code anymore cos it belongs to someone else, but the basic idea was using a WebClient to hit the domain default page, and check for a http status code of 200.
You can then wire any notification logic around the success or fail of this operation.
If bandwidth is a concern you can trim it back to just use a HEAD request.
For more complex sites that you control, you can wire up a health monitoring page that does some more in depth testing before it sends the response, eg is DB connection up etc.
Often a machine that is dead on port 80 will still respond to a ping, so testing port 80 (or whatever other one you are interested in) will be a much more reliable way to go.
我发现 ping 非常不可靠,因为您必须跳过所有的跃点,而中间的某些东西总是会干扰。
尝试打开与 Web 服务器的 http 连接可能是最好的方法。
I've found ping to be very unreliable just because of all the hops you're having to jump through, and something in between can always interfere.
Trying to open up an http connection with a web server is probably the best way to go.
如果您有 cygwin 可用,您可以尝试运行“httping”或
http://freshmeat.net/projects/httping/
You could try running 'httping' if you have cygwin available or
http://freshmeat.net/projects/httping/
据我所知,这里的问题是 OpenDNS 将无效域解析回自身,以便将您转发到接近您想要的内容(因此,如果您输入错误 ggooggllee.com,您最终会通过从OpenDNS 服务器)。 (如果我错了,请纠正我)
如果是这样的话,你应该能够检查你已经解析的IP是否== OpenDNS的任何IP? 不再需要 ping - 不再需要协议 (HTTP) 级别的内容 - 只是检查异常情况?
As far as I can see, the problem here that OpenDNS resolves invalid domains back to themselves to forward you on to something close to what you're after (so if you typo ggooggllee.com you end up at the right place via a bounce from the OpenDNS servers). (correct me if I'm wrong)
If that's the case, you should just be able to check whether the IP you've resolved == any of the IPs of OpenDNS? No more ping - no protocol (HTTP) level stuff - just checking for the exceptional case?
如果您倾向于系统管理解决方案而不是编程解决方案,您可以安装本地名称服务器并告诉它除了仅授权区域的 NS 记录之外不要接受任何内容。 这是我(我假设互联网上的其他人)在 Network Solution/Verisign 上次出现此问题时使用的修复程序。 我在几台本地计算机上安装了 BIND,告诉我的 DHCP 服务器将这些地址作为本地名称服务器分发,并为我关心的每个仅授权区域设置如下所示的内容:
想想看,我认为这可能会在以后的 BIND 版本中默认打开。 作为额外的好处,您往往会获得比大多数 ISP 提供的更稳定的 DNS 解析,您可以控制自己的缓存,进行一些修补,并且不必依赖 ISP 来修复最新的 DNS 攻击等。
If you tend toward the sys-admin solution rather than the programming solution you could install a local name server and tell it not to accept anything but NS records for delegation only zones. This was the fix I (and I assumed everyone else on the internet) used when Network Solution/Verisign broke this last time. I installed BIND on a couple of local machine, told my DHCP servers to hand out those addrs as the local name servers, and set up something like the following for each of the delegation only zones that I cared about:
Come to think of this, I think this might be turned on by default in later BIND versions. As an added bonus you tend to get more stable DNS resolution than most ISPs provide, you control your own cache, a little patching and you don't have to rely on your ISP to fix the latest DNS attack, etc.
我喜欢 CALM 来做这类事情,因为它会记录到数据库并提供电子邮件通知作为状态仪表板,
您可以在网站上设置一个测试页面,并定期在其上执行 GET 操作以接收“真实”结果(一切正常)或通过电子邮件发送给您的错误消息结果
警告:我是作者平静的
i like CALM for this sort of thing as it logs to a database and provides email notifications as well as a status dashboard
you can set up a test page on the site and periodically do a GET on it to receive either a 'true' result (all is well) or an error message result that gets emailed to you
caveat: i am the author of CALM