Grab common name from https://[ip]

D

DanimalEQ

Hello,

I checked around on here a bit, and was unable to find an answer to
this one by searching for the error message. I'm hoping someone here
can help me with this issue.

I am attempting to gather the common name from an SSL certificate for a
given IP address. Following is the code I am using thus far (two
classes being used):

IP_Justification.java:

import java.net.*; //for https connection
import java.io.*; //for input parsing
import javax.net.ssl.HttpsURLConnection;

public class IP_Justification
{
private String IP; //IP address to search
private String domain; //common name returned by viewing IP via
https://ip

//default constructor
public IP_Justification()
{
throw new IllegalArgumentException("Please provide IP and domain");
}

//create with IP provided
public IP_Justification(String ip)
{
IP = ip;
domain = "";
}

public void getDomain() throws IOException
{
String urlToCheck = "https://" + IP;
URL techURL = new URL(urlToCheck);
System.out.println("URL created: " + techURL);

HttpURLConnection techUrlConn =
(HttpURLConnection)techURL.openConnection();
System.out.println("HttpURLConnection created" + techUrlConn + "\n");
techUrlConn.connect();
}
}

IPJustMain.java
import java.io.*;

public class IPJustMain
{
public static void main(String[] args) throws IOException
{

IP_Justification testing;
testing = new IP_Justification("64.233.167.99");
testing.getDomain();
try
{

}
catch(Exception e)
{
System.out.println("Start of output - Exception block");
System.out.println(e.getMessage());
System.out.println("End of output - Exception block");
}
}
}


Following is the output received when running IPJustMain:


URL created: https://64.233.167.99
HttpURLConnection
createdsun.net.www.protocol.https.DelegateHttpsURLConnection:h
ttps://64.233.167.99

Exception in thread "main" java.io.IOException: HTTPS hostname wrong:
should be
<64.233.167.99>
at
sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.j
ava:490)
at
sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:
415)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:170)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLCon
nectionImpl.java:133)
at IP_Justification.getDomain(IP_Justification.java:54)
at IPJustMain.main(IPJustMain.java:15)
Press any key to continue . . .


I fully expect to have an exception thrown, and am hoping to be able to
parse that for the information I require. The problem I am running
into is the exception itself:

Exception in thread "main" java.io.IOException: HTTPS hostname wrong:
should be
<64.233.167.99>

It seems to be responding with the URL I pass to it, and not the common
name for the SSL at the specified IP address.

Anyone happen to know if there is a way around this or if my code is
flawed in someway?

Thanks for any help that can be provided!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top