Starstepper
Starstepper

Reputation: 144

Getting ip from specific URL

I'm trying to get the IP address of a specific url using:

var ip = Dns.GetHostAddresses("http://oldschool.runescape.com/game?world=321")[0];

The problem is that this function only seems to work with the normal host adress (as the function tells, ex: www.runescape.com) which creates an exception when using this specific more deeper URL. Is there any function to get the IP of a more specific URL?

Thanks in advance.

Upvotes: 9

Views: 20625

Answers (2)

woundjuice
woundjuice

Reputation: 41

I am not an expert on DNS, however the "more specific" URL should be irrelevant as the IP for the host node is all you should need to care about. The rest of the subdomains still reside on the same box and should have the same IP Address. If for whatever reason what you are looking for is a hosted service within that domain, then it will have a different URL completely.

an NSLOOKUP for example would only return the root domain;

DNS server handling your query: localhost DNS server's address: 127.0.0.1#53

Non-authoritative answer: oldschool.runescape.com canonical name = runescape.com. Name: runescape.com Address: 91.235.140.130

However I do see that the URL you provided does redirect elsewhere to: http://oldschool.runescape.com/slu

Hope this helps.

Upvotes: 0

prospector
prospector

Reputation: 3469

The full url like that will have the same hostname. As easy way to get the hostname is this:

var url = "http://oldschool.runescape.com/game?world=321";
Uri myUri = new Uri(url);
var ip = Dns.GetHostAddresses(myUri.Host)[0];

Simply extract the host out of the url and that should prevent your error giving you the correct Ip address of the host.

Upvotes: 20

Related Questions