0

I'm writing a local Proxy server. It already works for the majority of the requests. But sometimes I have Problems when I want to resolve the Host-name. Here is what I do:

When the header of the request is received, I filter the first line out. Then I take the Request-URL (which is between the two spaces) out of that line and store it into an Uri object. After that I extract the hostname with: string host= uri.host; At least I do the DNS-call: IPAddress[] ips = Dns.GetHostAddresses(host)[0]; (How do I know here, which IP of the array I should take. Whats the difference between those IP's)

Like I said, for the majority of the Requests that works fine. But there are some adresses, that cannot be resolved. Here an example: When I want to open www.gmx.net, I first get the HTML-File ( this works fine ). After that, the Browser reloads a couple of Web-Objects like pics, javascript and so on. Those Object of course have some URL. And one of those URLs, that cannot be resolved is: ipv4-cout.gmx.net . The attempt to resolve this URL results in the warning: The stated Host is unknown.

Another thing I need to know is: How to handle Alias-Host-names? For example: When I enter the hostname gmx.de into the Browser, it automaticaly resolves it into www.gmx.net. I know, there are Recource Reccords on a DNS-Server with type CNAME, but I dont know how to implement this.

4

1 回答 1

0

我会说它们是按照 DNS 服务器发送它们的顺序返回的,我找不到任何特定顺序的参考。

Dns.GetHostAddresses 方法

在大多数情况下,只有一个 IP 地址。在 www.gmx.net 的情况下,他们确实有 2 个,理论上,这意味着您将循环请求。

www.gmx.net has address 212.227.223.5
www.gmx.net has address 212.227.223.4

供您参考。pv4-cout.gmx.net 无法在我的机器上解析,并且在以任何其他方式访问时会导致 404。

gmx.de 无法解析为 www.gmx.net,Web 服务器上有一个 URL 重定向。

Connecting to www.gmx.de|212.227.223.10|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.gmx.net/ [following]
于 2012-11-22T15:00:37.287 回答