编写一个C#脚本来测试数百个域名

发布于 2024-08-03 10:59:47 字数 221 浏览 12 评论 0原文

一位客户给了我一份包含数百个域名的电子表格。

我的任务是确定每个域的以下内容:

  • 哪些域连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏有森光若流苏 2024-08-10 10:59:47

您可以使用 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.

〃安静 2024-08-10 10:59:47

为此,我使用了以下内容:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.AllowAutoRedirect = false; // allows tracking of redirects
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string server = resp.Headers["Server"]; // to track server software
string poweredby = resp.Headers["X-Powered-By"]; //denotes ASP.NET, PHP, etc
string aspnetVersion = resp.Headers["X-AspNet-Version"]; //only applies to IIS servers

可以捕获一些附加响应标头以获取更多信息:

http:// /en.wikipedia.org/wiki/List_of_HTTP_headers

To do this, I used the following:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.AllowAutoRedirect = false; // allows tracking of redirects
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string server = resp.Headers["Server"]; // to track server software
string poweredby = resp.Headers["X-Powered-By"]; //denotes ASP.NET, PHP, etc
string aspnetVersion = resp.Headers["X-AspNet-Version"]; //only applies to IIS servers

Some additional response headers that could be capture for more info:

http://en.wikipedia.org/wiki/List_of_HTTP_headers

煮茶煮酒煮时光 2024-08-10 10:59:47

您的大多数需求都可以通过 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).

音盲 2024-08-10 10:59:47

关于你的第二项

•其中,重定向到另一个站点。

HttpWebRequest/Response 和 WebClient 将捕获大多数重定向,但不是全部,因为有些页面通过 JavaScript 进行重定向。由于它们都不执行 JavaScript,因此您将无法检测到这些情况,除非您使用 WebBrowser 控件或其他能够运行 JavaScript 的控件。

With respect to your 2nd item

•Of those that are, which redirect to another site.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文