import java.io.*;
import java.net.*;
import java.util.*;
public class testprop {
public static void main (String args[])
throws IOException, URISyntaxException {
// to check wether proxy working or not
Properties p = System.getProperties();
p.setProperty("proxySet", "true");
p.put("https.proxyHost","proxy servername");
p.put("https.proxyPort","80");
System.setProperties(p);
//if i uncomment the below line i am getting Glib GIO error org.gnome.system.proxy is not installed
//System.setProperty("java.net.useSystemProxies", "true");
try {
Proxy p1= (Proxy) ProxySelector.getDefault().select(new URI("http://google.com")).iterator().next();
System.out.println("ProxyString"+p1.type());
InetSocketAddress addr=(InetSocketAddress)p1.address();
if(addr==null)
System.out.println("no proxy");
else{
System.out.println("Proxy hostname" +addr.getHostName());
System.out.println("Proxy port" +addr.getPort());
}
System.out.println("done");
} catch (URISyntaxException uo){
System.out.println("done3");
}
String str="google.com";
try{
InetAddress ip=InetAddress.getByName(str);
System.out.println("the ip address of servicenow is"+ip);
}catch (UnknownHostException ue){
ue.printStackTrace();
System.out.println("website not found");
}
}
}
I am in an enterprise network,so to access internet I have to go through proxy.The above code is not setting the proxy for the next connection.Throwing an unknown host exception.
Is there any way I can achieve this?
Setting proxy so that external URL will be passed through proxy server.
Out put of the above code:
output:
ProxyStringDIRECT
no proxy
done
java.net.UnknownHostException: google.com: No address associated with hostnamewebsite not found
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
at java.net.InetAddress.getAllByName(InetAddress.java:1162)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at java.net.InetAddress.getByName(InetAddress.java:1048)
at testprop.main(testprop.java:49)
Related
i wanted to make an easy LDAP Connection with using Apache DS and Java, wanted to learn and play a bit with authentification. However, when i start using the my jar file, i always get this error message:
Setting up LDAP connection ...
LDAPException(resultCode=91 (connect error), errorMessage='An error occurred while attempting to resolve address 'ldap://localhost:10389':
UnknownHostException(Der angegebene Host ist unbekannt (ldap://localhost:10389)), ldapSDKVersion=6.0.0, revision=524c20f3bbcc0d83fb56b9e136a2fd3a7f60437d')
My apache DS LDAP server looks like this:
enter image description here
My Java code:
package ldap.test;
import java.security.GeneralSecurityException;
import javax.net.SocketFactory;
import com.unboundid.ldap.sdk.BindRequest;
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPSearchException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.SimpleBindRequest;
import com.unboundid.util.ssl.SSLUtil;
import com.unboundid.util.ssl.TrustAllTrustManager;
public final class App2 {
// hostname of the ldap instance
public static final String HOSTNAME = "ldap://localhost:10389";
// port of the ldap instance
public static final int PORT = 10389;
public static final void main(String[] args)
{
// lazy hack
if ( args.length != 4 ) {
System.out.println("One or more parameters are missing!");
System.out.println("java -jar App2.jar $cn $sn $employeenumber $password");
System.out.println("Example: java -jar App2.jar Max Mustermann 1 1");
System.exit(1);
}
// Use no key manager, and trust all certificates. This should not be used in non-trivial code!
SSLUtil sslUtil = new SSLUtil(null, new TrustAllTrustManager());
SocketFactory socketFactory;
LDAPConnection ldapConnection = null;
try {
// Create the socket factory that will be used to make a secure
// connection to the server.
socketFactory = sslUtil.createSSLSocketFactory();
System.out.print("Setting up LDAP connection ... ");
ldapConnection = new LDAPConnection(socketFactory, HOSTNAME, PORT);
System.out.println("done!");
}
catch ( LDAPException ldapException ) {
System.err.println(ldapException);
System.exit(ldapException.getResultCode().intValue());
}
catch ( GeneralSecurityException exception ) {
System.err.println(exception);
System.exit(1);
}
// LDAP bindrequest and actual bind for DN search
System.out.print("Search DN for user with employeeNumber: " + args[2] + " ... ");
BindRequest ldapBind = new SimpleBindRequest(args[0], args[1]);
try {
// bind with technical user and password and search for DN
ldapConnection.bind(ldapBind);
String employeeNumber = args[2];
String userPassword = args[3];
Filter ldapFilter = Filter.createANDFilter(Filter.createEqualityFilter("number", employeeNumber));
SearchRequest searchReq = new SearchRequest("ou=users,o=Beispiel", SearchScope.SUB, ldapFilter, "dn");
SearchResult searchResult;
String foundDN = "none";
try
{
searchResult = ldapConnection.search(searchReq);
System.out.println("done!");
for ( SearchResultEntry entry : searchResult.getSearchEntries() )
{
foundDN = entry.getDN();
}
}
catch ( LDAPSearchException lse )
{
System.out.println("... error!");
// The search failed for some reason
searchResult = lse.getSearchResult();
ResultCode resultCode = lse.getResultCode();
System.out.println("Resultcode: " + resultCode);
String errorMessageFromServer = lse.getDiagnosticMessage();
System.out.println("Error message from server: " + errorMessageFromServer);
}
// now check for the foundDN if the given password is correct
if ( !foundDN.equals("none") ) {
System.out.println("Found DN for user with EmployeeNumber: " + employeeNumber + " => " + foundDN);
System.out.println("Now checking if password for user is correct!");
BindRequest userBindReq = new SimpleBindRequest(foundDN, userPassword);
BindResult userBindRes = ldapConnection.bind(userBindReq);
System.out.println("Result: " + userBindRes);
}
else {
System.out.println("No DN found for user with EmployeeNumber: " + employeeNumber);
}
}
catch ( LDAPException ldapException ) {
System.err.println(ldapException);
System.exit(ldapException.getResultCode().intValue());
}
finally {
// Close ldap connection
ldapConnection.close();
}
}
}
No idea why i cant connect to the server...
-----Edit--------
When i change the HOSTNAME to localhost, i get the following error message:
Setting up LDAP connection ... LDAPException(resultCode=91 (connect error),
errorMessage='An error occurred while attempting to connect to server localhost:10389: IOException(LDAPException(resultCode=91 (connect error),
errorMessage='An error occurred while attempting to establish a connection to server localhost/127.0.0.1:10389: SSLException(Unsupported or unrecognized SSL message),
ldapSDKVersion=6.0.0, revision=524c20f3bbcc0d83fb56b9e136a2fd3a7f60437d'))')
Well the good thing is that he can find localhost, but he cant connect to the server
I faced a similar issue, and the problem was solved by calling the LDAPConnection constructor with only two arguments ("localhost",10389). Could you check if this resolves your issue too?
Ofcourse, you should also remove the "ldap//:" prefix too!
I have deployed a secure ejb on machine1, when I run the client code on the same machine, it works fine. But when I run the client code on any other machine it throws an error. which is pasted below.
In the error it can be seen that its not taking the ip: that is provided but instead it looks in the client machine itself. Where is the problem is it in the client code or am I missing some settings in WebSphere.
package org.was.tutorial.security.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.was.tutorial.security.bean.Calculator;
public class Client
{
public static void main(String[] args) throws Exception
{
//Establish the proxy with an incorrect security identity
Properties env = new Properties();
//username and password
//String username="teacher1";
//String password="teacher";
String username="student1";
String password="student";
//setting up environment properties..
env.setProperty(Context.SECURITY_PRINCIPAL, username);
env.setProperty(Context.SECURITY_CREDENTIALS, password);
env.setProperty(javax.naming.Context.PROVIDER_URL, "iiop://10.94.13.18:2809");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
//javax.rmi.PortableRemoteObject.narrow(ctx.lookup("CalculatorBean/remote"), Calculator.class);
Calculator calculator =null;
try{
calculator = (Calculator)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("CalculatorBean/remote"), Calculator.class);
if(calculator==null){
System.out.println("This is not going anywhere");
}else
System.out.println("Good. we made a progress.");
}catch (Exception e) {
e.printStackTrace();
}
System.out.println("User "+username);
System.out.println("Addition can be performed by all");
try
{
System.out.println("1 + 1 = " + calculator.add(1, 1));
}
catch (Exception ex)
{
System.out.println("Saw expected SecurityException: " + ex.getMessage());
}
System.out.println("Subtraction- can be performed by students only.");
try
{
System.out.println("16- 4 ="+calculator.subtract(16, 4));
}catch (Exception ex)
{
System.out.println(ex.getMessage());
}
System.out.println("Division- can be performed by teachers only.");
try
{
System.out.println("16/4 ="+calculator.divide(16, 4));
}catch (Exception ex)
{
System.out.println(ex.getMessage());
}
///cool
}
}
Error:
Exception in thread "P=13152:O=0:CT" javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1552)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:1042)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:962)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:614)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:128)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:765)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:164)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:423)
at com.temenos.services.ofsconnector.ejb.IntegrationFrameworkServiceClient.main(IntegrationFrameworkServiceClient.java:50)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1109)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1463)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1001)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1429)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1618)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1385)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:458)
at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1549)
... 9 more
Caused by: org.omg.CORBA.COMM_FAILURE: CONNECT_FAILURE_ON_SSL_CLIENT_SOCKET - JSSL0130E: java.io.IOException: Signals that an I/O exception of some sort has occurred. Reason: Connection refused: connect Remote Host: 127.0.0.1 Remote Port: 9403 vmcid: 0x49421000 minor code: 80 completed: No
at com.ibm.ws.security.orbssl.WSSSLClientSocketFactoryImpl.tryToCreateConnectedSSLSocket(WSSSLClientSocketFactoryImpl.java:357)
at com.ibm.ws.security.orbssl.WSSSLClientSocketFactoryImpl.createSSLSocket(WSSSLClientSocketFactoryImpl.java:219)
at com.ibm.ws.orbimpl.transport.WSSSLTransportConnection.createSocket(WSSSLTransportConnection.java:236)
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:348)
at com.ibm.ws.orbimpl.transport.WSTransport$1.run(WSTransport.java:503)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.orbimpl.transport.WSTransport.getConnection(WSTransport.java:500)
at com.ibm.CORBA.transport.TransportBase.getConnection(TransportBase.java:181)
at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:97)
at com.ibm.rmi.iiop.GIOPImpl.getConnection(GIOPImpl.java:134)
at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:230)
at com.ibm.rmi.corba.ClientDelegate.locate(ClientDelegate.java:1696)
at com.ibm.rmi.corba.ClientDelegate._createRequest(ClientDelegate.java:1721)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1023)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1105)
... 17 more
Update
I have created the node and profile using the following script:
File1:setUpEnv.bat
set WAS_HOME=C:\IBM\WebSphere\AppServer
set HOST_NAME=localhost
set PROFILE_NAME=AppSrv01
set NODE_NAME=%PROFILE_NAME%Node01
set CELL_NAME=%NODE_NAME%Cell
set SERVER_NAME=server1
set DMGR_USER=user1
set DMGR_PASSWORD=123456
set DMGR_HOST=localhost
set DMGR_PORT=8879
File2:
CALL ./setUpEnv.bat
set WAS_HOME=C:\IBM\WebSphere\AppServer
CALL %WAS_HOME%\bin\manageprofiles.bat -create -profileName %PROFILE_NAME% - profilePath %WAS_HOME%\profiles\%PROFILE_NAME% -templatePath %WAS_HOME%\profileTemplates\default -serverName %SERVER_NAME% -cellName %CELL_NAME% -nodeName %NODE_NAME% -hostName %HOST_NAME% -enableAdminSecurity true -adminUserName %DMGR_USER% -adminPassword %DMGR_PASSWORD%
The 9403 is correct port for RMI/IIOP SSL communication (CSIV2_ SSL_ SERVERAUTH_ LISTENER_ ADDRESS). It might happen that you incorrectly installed WAS using localhost, and it sends to the client redirection for the localhost instead for its host name.
Double check WAS configuration for example via web console, in the Server -> Administration -> ports section.
If you installed WAS using localhost, you will either have to change host, or recreate provile (the second might be easier if you are a new to WAS).
I just started working in Java networking protocols. I am trying to connect to the internet using my proxy server. When I see the post at 'https://www.tutorialspoint.com/javaexamples/net_poxy.htm', they set the http.proxyHost property to 'proxy.mycompany1.local'. I know I can set this to my proxy server IP, but I am curious to know why my program still works, even though I set it to some random string like "abcd".
A. What does 'proxy.mycompany1.local" stand for?
B. How come my program works, even though I set the http.proxyHost" to "abcd"?
Following is my working program:
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URL;
public class TestProxy {
public static void main(String s[]) throws Exception {
try {
System.setProperty("http.proxyHost", "abcd");
System.setProperty("http.proxyPort", "8080");
URL u = new URL("http://www.google.com");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());
} catch (Exception e) {
e.printStackTrace();
System.out.println(false);
}
Proxy proxy = (Proxy) ProxySelector.getDefault().select(new URI("http://www.google.com")).iterator().next();
System.out.println("proxy Type : " + proxy.type());
InetSocketAddress addr = (InetSocketAddress) proxy.address();
if (addr == null) {
System.out.println("No Proxy");
} else {
System.out.println("proxy hostname : " + addr.getHostName());
System.out.println("proxy port : " + addr.getPort());
}
}
}
This is the output:
200 : OK
proxy Type : HTTP
proxy hostname : abcd
proxy port : 8080
First of all, according System Properties tutorial.
Warning: Changing system properties is potentially dangerous and
should be done with discretion. Many system properties are not reread
after start-up and are there for informational purposes. Changing some
properties may have unexpected side-effects.
And my experience say you can get unpleasant issues on your system when you change *.proxyHost properties. So I highly wouldn't recommend you to change system properties for this task.
Much better use something like:
//Proxy instance, proxy ip = 127.0.0.1 with port 8080
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080));
conn = new URL(urlString).openConnection(proxy);
and authorisation on proxy:
Authenticator authenticator = new Authenticator() {
#Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user",
"mypassword".toCharArray());
}
};
Authenticator.setDefault(authenticator);
Now return to main questions:
A. 'proxy.mycompany1.local" is just example. You can use any hostname
B. Class URL uses java.net.PlainSocketImpl class via Socket. It tries to resolve proxy hostname 'abcd', swallow error and go to google directly. Just try to play with this code:
import java.net.*;
import java.io.*;
public class RequestURI {
public static void main(String[] args) {
int port = 8181;
long startTime = System.currentTimeMillis();
try {
// System.getProperties().setProperty("http.proxyHost", "abcd");
// System.getProperties().setProperty("http.proxyPort", Integer.toString(port));
URL url = new URL("http://google.com");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
int resp = uc.getResponseCode();
if (resp != 200) {
throw new RuntimeException("Failed: Fragment is being passed as part of the RequestURI");
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Run time in ms ="+ (System.currentTimeMillis() - startTime));
}
}
You can see run time is bigger when you uncomment section with setProperty. Unsuccessful attempt to resolve hostname increases execution time.
First of all, proxy.mycompany1.local is just a host name, it is a sample, it is nothing special.
I tried your code in a non proxied network, and it worked as you described. I guess that url.openConnection() method ignores proxy settings, because if you manage your own proxy and use url.openConnection(proxy), then it fails with a java.net.UnknownHostException.
Here you are with a piece of code that fails:
SocketAddress addr = new InetSocketAddress("abcd", 8080);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
URL url = new URL("http://google.com");
URLConnection conn = url.openConnection(proxy);
InputStream in = conn.getInputStream();
in.close();
You can read more about Java Networking and Proxies.
I am not so experienced in Java RMI. I am trying to implement simple RMI communication, but faced with the problem.
Here my RMI client
public class MainClientApplication {
public static final String FILE_NAME_RMI_POLICY = "rmi.policy";
public static final String RMI_DOMAIN = "mydomain.net";
public static final String RMI_ENDPOINT = "/MD5Decrypter";
public static final String PROTOCOL = "rmi://";
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
System.setProperty("java.security.policy", System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
String remoteHost = String.format("%s%s%s", PROTOCOL, RMI_DOMAIN, RMI_ENDPOINT);
System.setSecurityManager(new SecurityManager());
try {
ComputeEngine computeEngine = (ComputeEngine) Naming.lookup(remoteHost);
SwingUtilities.invokeLater(() -> new MainWindow("MD5 Decryption", computeEngine));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Communication inerface
public interface ComputeEngine extends Remote {
Object executeTask(Task t) throws RemoteException;
}
My server
public class MainServer {
public static final int PORT = 1099;
public static final String RMI_ENDPOINT = "MD5Decrypter";
public static final String FILE_NAME_RMI_POLICY = "rmi.policy";
public static final String RMI_DOMAIN = "mydomain.net";
public static final String PROTOCOL = "rmi://";
public MainServer() {
try {
System.setProperty("java.security.policy", System.getProperty("user.dir") + File.separator + FILE_NAME_RMI_POLICY);
//System.setProperty("java.rmi.server.hostname", RMI_IP);
System.setProperty("java.rmi.server.hostname", RMI_DOMAIN);
System.setSecurityManager(new SecurityManager());
ComputeEngine computeEngine = new ComputeEngineExecutor();
// Naming.rebind(String.format("%s%s:%d/%s", PROTOCOL, RMI_DOMAIN, PORT, RMI_ENDPOINT), computeEngine);
Naming.rebind(RMI_ENDPOINT, computeEngine);
System.out.println("Successfully started RMI Server");
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
MainServer mainServer = new MainServer();
}
}
And rmi.policy
grant {
permission java.net.SocketPermission "*:1024-65535", "connect, accept";
permission java.io.FilePermission "-", "read";
permission java.net.SocketPermission "*:80", "connect";
};
So I have started rmiregistry on my server rmiregistry 1099. And everything works well until calling remote object method.
Here are my steps
Lets consider that my domain is mydomain.net , I host it on my server at home with static IP.
Run rmiregistry on the server
Run server application on the server
Run client application on any PC
Click button to invoke remote method
So it seems that everything connects and binds successfully, because if force enter invalid domain, endpoint or refused if rmiregistry is not started - java.rmi.ConnectException is thrown.
But when I try to invoke any method on remote object, BTW which has been already retrieved successfully it throws a java.rmi.ConnectException
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy0.executeTask(Unknown Source)
at ui.MainWindow.lambda$initGui$0(MainWindow.java:49)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
As I can understand the problem is that it (server) forces me to connect to my localhost instead of remote.
P.S on localhost everything works perfectly (both client and server on the one PC)
Please help to solve this problem.
EDIT
I have forgotten to tell that I have tried to set property of java.rmi.server.hostname, in this case it takes a lot of time to start the server and ends with exception.
Leaving the 127.0.0.1 issue aside, which is solved by java.rmi.server.hostname, your problem now is connect timeouts. This will be caused by your firewall. You need to export your remote object on a specific port, and you need to open that TCP port in your firewall.
My computer name is D*******.
When it is not connected to VPN client it gives same ip address from ipconfig and www.jsonip.com too.
But when I connect to VPN client the ip4 address changes to ppp adapter ip address, whereas the www.jsonip.com site still retrieves Ethernet ip4 address.
Is there a javascript or java way to get ip address via resolving the Computer Name?
JAVA check this..
import java.net.InetAddress;
public class GetIPAddress {
public static void main(String[] args) {
try {
InetAddress thisIp = InetAddress.getLocalHost();
System.out.println("IP:" + thisIp.getHostAddress());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Another JAVA sample Code
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
Address = InetAddress.getByName("google.com");
System.out.println(Address);
For JS Try this javaScript code it might help you.
Superuser
http://jsfiddle.net/
Try this.
import java.net.InetAddress;
class IPAddress
{
public static void main(String args[]) throws Exception
{
System.out.println(InetAddress.getLocalHost());
}
}