none
Find URL from an IP address. RRS feed

  • Question

  • This seems like it should be an easy thing to do, but the solution doesn't seem obvious. Given an IP address I want to turn that IP address into a URL. How can I do this in C#?

    Thank you for your help.


    Ben Holtzman

    Saturday, April 2, 2016 5:36 AM

Answers

All replies

  • Hi Ben Holtzman,

    You can try this way to do that:

     IPHostEntry IpEntry = Dns.GetHostByAddress(ip); 
     return iphostentry.HostName.ToString();

    More explanation about this code is here: http://www.c-sharpcorner.com/UploadFile/uchukamen/IPAddHostConverter12052005041212AM/IPAddHostConverter.aspx

    Best regards!

     

    (If this was helpful for you, vote for it and propose it as an answer)

    • Proposed as answer by User3DX Saturday, April 2, 2016 7:49 AM
    • Marked as answer by Ben Holtzman Sunday, April 3, 2016 2:00 AM
    Saturday, April 2, 2016 7:01 AM
  • You can do a reverse DNS lookup to get the domain/hostname associated with one IP adress. However that will only get you the domain/hostname part of the URL, not the other 2-6 parts of the URL.
    Replacing the computer friendly IP adress with a human friendly domain/host name is the only job of the DNS service.

    However, not every IP adress has one entry and some might have multiple.
    Common mispellings are often added the DNS lists, with the same IP adress.
    And a computer/router that does not need to be reachable via a browser has a IP adress, but no DNS entry.

    Saturday, April 2, 2016 8:54 PM
  • This is very similar to what I had attempted. If I ping a known URL, say www.craigslist.org, I'm told that the IP address is 208.82.237.129. Putting that IP address into the etHostByAddress() method returns www.craigslist.org. Great! This is exactly what I'm looking for.

    The compiler is warning me that the method Dns.GetHostByAddress() is obsolete and recommends that I use Dns.GetHostEntry() instead. If I try to use the recommended method, I'm told that the HostName = www.l.craigslist.org which doesn't resolve to a URL I can browse to. Any idea why the original version which produces usable results is being replaced with something that, at least on the surface doesn't seem to produce usable results?

    I'm marking this as the answer, since it does answer the original question. Thank you Almir!


    Ben Holtzman


    • Edited by Ben Holtzman Sunday, April 3, 2016 5:26 AM original message was unclear.
    Sunday, April 3, 2016 2:00 AM
  • That's good to know. I do see an address collection inside the IPHostEntry object. I don't see a collection of HostNames though. I wonder what that means? Thanks Christopher. :)

    Ben Holtzman

    Sunday, April 3, 2016 2:05 AM
  • That's good to know. I do see an address collection inside the IPHostEntry object. I don't see a collection of HostNames though. I wonder what that means? Thanks Christopher. :)

    Ben Holtzman

    I am mostly going by memory and third party information here, but some other wierd stuff can happen with DNS.
    Like having multiple IP adresses behind on Domain name.
    I heard of something even wierder, where one IP adress is shared by multiple servers.

    The idea is that whoever asks for it can ping them all and just talk with the one that answers fastest - wich presumably is the closest.

    Google in particular has more then one server per country. It is a necessity to balance the load as no single server could be powerfull enough to serve every requests for a country.

    Sunday, April 3, 2016 2:17 AM