编写一个C#脚本来测试数百个域名
一位客户给了我一份包含数百个域名的电子表格。
我的任务是确定每个域的以下内容:
- 哪些域连接到 Web 服务器/网站。
- 其中,重定向到另一个站点。
- 运行的服务器软件是什么(ASP、ASP.NET、Apache 等)
...并以有组织的方式输出结果。
有没有一个脚本(最好是 C#)可以帮助解决这个问题?
A client has given me a spreadsheet of hundreds of domain names.
My task is to determine the following about each:
- Which domains are connected to a web server / website.
- Of those that are, which redirect to another site.
- What is the server software running (ASP, ASP.NET, Apache, etc)
...and output the results in an organized fashion.
Is there a script, preferably c#, that can help with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 HttpWebRequest 类来测试域名称。根据 HttpWebResponse 的 HttpStatus 属性,您可以决定是否存在重定向。
在某些情况下,您可能能够通过查看随响应发送的标头来找出服务器软件,但可能并非所有(或只有少数)服务器都发送这些标头。
You could use the HttpWebRequest class to test the domain names. Based on the HttpStatus property of the HttpWebResponse you can decide whether there is a redirect.
For some cases you might be able to find out the server software by looking at the headers sent with the response, but probably not all (or only a few) servers send these headers.
为此,我使用了以下内容:
可以捕获一些附加响应标头以获取更多信息:
http:// /en.wikipedia.org/wiki/List_of_HTTP_headers
To do this, I used the following:
Some additional response headers that could be capture for more info:
http://en.wikipedia.org/wiki/List_of_HTTP_headers
您的大多数需求都可以通过 System.Net.WebClient 类来处理。一个棘手的问题是该网站使用什么服务器软件。即使您运行直接查询服务器的程序,您也无法可靠地判断它正在使用什么服务器软件,因为该软件通常可以配置为欺骗您并告诉您并模仿另一个常见服务器品牌的响应。虽然撒谎并不常见,但也并非闻所未闻(有些人认为撒谎是摆脱困境的最佳做法)。
Most of your requirements can be handled via the
System.Net.WebClient
class. The one sticky point is what server software the site uses. Even if you run something that queries the server directly, you can't reliably tell what server software it's using because that software can usually be configured to lie to you and tell you and mimic the response of another common server brand. And while lying isn't common, it's not unheard of, either (it's considered by some to be a best practice as a way to throw off crackers).关于你的第二项
HttpWebRequest/Response 和 WebClient 将捕获大多数重定向,但不是全部,因为有些页面通过 JavaScript 进行重定向。由于它们都不执行 JavaScript,因此您将无法检测到这些情况,除非您使用 WebBrowser 控件或其他能够运行 JavaScript 的控件。
With respect to your 2nd item
HttpWebRequest/Response and WebClient will catch most of the redirects but not all of them since there are pages that do the redirect via JavaScript. Since neither of them executes JavaScript, you'll not be able to detect these cases unless you use a WebBrowser control or something else capable of running JavaScript.