title: how to create a URL object using an InetAddress object in Java?
body: <p>I have a need to create a http or https URL object from an IPv4 address (String or InetAddress objects - either one is ok) in Java. I have been at this for 10 hours now.</p>
  
  <p>Attempts that hit a wall described below:</p>
  
  <ol>
  <li><p>Attempt #1: I tried to make the URL by assembling a string, and then feeding it to a URL constructor.</p>
  
  <ul>
  <li>Textbook states that a URL can be "protocol://host", with host being either a host name or IP address. but creating a URL like this: <code>URL a = new URL("http://151.101.65.69");</code> and opening a stream to this URL (<code>a</code>) gives a HTTP error 500 (Internal Server Error - An unexpected condition occurred that the server does not know how to handle).</li>
  <li>What get me fuming is that <code>URL a = new URL("http://stackoverflow.com");</code> works.</li>
  <li>At this point I am stuck. I have no Idea what to change, or how to move forward.</li>
  </ul></li>
  <li><p>Attempt #2: I tried to do a reverse lookup on the IP address using "getHostName()" method in the InetAddress class. </p>
  
  <ul>
  <li>this should return the host name by doing a reverse DNS lookup. Yet, I keep trying it for 151.101.65.69 (stackoverflow web server IP address), and the look up fails. By fails I mean the IP address is returned as string rather than the host name as a string. I read the Oracle docs <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/net/InetAddress.html#getHostName()" rel="nofollow noreferrer">http://docs.oracle.com/javase/1.5.0/docs/api/java/net/InetAddress.html#getHostName()</a>, but I don't understand how to overcome the "security manager" the document mentions (or if it is indeed the reason the reverse lookup fails).</li>
  <li>I also tried "getCannonicalHostName()", but that didn't fly either.</li>
  </ul></li>
  <li><p>I am trying to figure out how to open a website using the IP address. It looks like my browser is running into the same issue as my code. I read up on <a href="https://stackoverflow.com/questions/22043602/how-to-access-site-through-ip-address-when-website-is-on-a-shared-host">How to access site through IP address when website is on a shared host?</a> but I do not have any user names, as I want to  be able to open any website that a user has an IP address for. Adding a port (such as 80) does not seem to work; neither does leaving the user name blank or using a generic 'user' or 'guest'.</p></li>
  </ol>
  
  <p>I need is to create a URL object from an IPv4 String or InetAddress object, and I am stuck. I understand that a knowledgeable programmer such as you, may say that making URLs from IP addresses is not what IP addresses are for, or point out that I am not including a file portion of the URL, but that is not the problem at this moment. Could you please help me with my core challenge?</p>