Get the system Ip

URLConnection.setConnectTimeout(int timeout)

timeout value is in milliseconds.

Your code has


Do you mean 10 miliseconds?
Maybe not.
If you want 10 seconds, then you should write


I just removed the line “conn.setConnectTimeout(10)” and tried; it ran successful. So you don’t need to specify the connection timeout explicitly.

The following code will return the IP Address for the Given URL

String url=“
InetAddress ia=InetAddress.getByName(url)
String ip=ia.getHostAddress()

or Use

URL url = new URL(“”);
URLConnection conn = url.openConnection();

conn.setRequestProperty(“accept-language”, “en-US,en;q=0.9”);
conn.setRequestProperty(“user-agent”, “MyJavaApp”);
InputStream ins = url.openStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader websiteText = new BufferedReader(isr);

}catch(Exception e)


The above code will print the IP address of the remote host “”, which is not the one the original poster wants.

On the other hand is a special URL which responds a string that contains the IP address of the requester, which is most probably your local PC.

This code will give you your local ip then ?

1 Like

I don’t see what you mean “your local ip”

As for “”, see

The service provides the public IP address of the client making the request.

I tried this code and it failed. The connection failed to esstablish due to the line


How to fix? You want to remove this line, or rewrite it to


What do you mean by ‘local IP’?
This has to be clarified first.
E.g in my linux machine i can run something like:

$ ip a
4: enp7s0f3u1u1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 3c:e1:a1:4a:c8:5b brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic noprefixroute enp7s0f3u1u1
       valid_lft 78609sec preferred_lft 78609sec
    inet6 fe80::c416:ace4:bcdb:4ca8/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

This will provide me the IP addresses assigned to my networking cards and I filtered the output for the one currently in use.
I will name this ‘local IP’. Note that it may not be a single value.
It can change based on my local router settings (and ofcourse, based on the networking card in use, wifi, lan1, lan2 etc)

If this is the case, you may like to take a look at the discussions here:

Hower, on internet I appear a bit different, due to the other various gateways in place up to the internet provider.
So doing something like:

$ host
Using domain server:
Address: XXX.XXX.XXX.XXX#53
Aliases: has address YYY.YYY.YYY.YY

Gives me some other values, the IP of the DNS resolver in use (xxx) and the public IP, as internet ‘see me’ (the YYY, whiuch should be same regardless of the query service I may use)
This can change based on the Internet provider settings and networking details, e.g if I am connected to VPN or not.

So, which one do you actually neeed?
Once we have this answer, we can look for a propper java solution, the proposed solutions up to now are returning just the public IP by using the AWS resolver, which is a public service.

I’m not getting any error and I added this solution because he tried to get IP from the same code he shared.

1 Like

The value in the ‘output’ is a public IP. Period.
Aside of that, since it starting with 34. looks like is an AWS public IP. I doubt it is the actual value you need … but what do I know.
Compare that with what you may get by typing on Google ‘my ip’ and look for something like:

Another period.

If you are happy with it, that’s fine.

How long the timeout value of URLConnection.setConnectionTimeout(int timeout) will be in usal cases? See the following post, for example,

They write


timeout of 15 seconds looks usual to me. But, may be, too long?.

To me,


does not make a good sense. This requires super high-speed network connection to the public Internet.

In my case, the code failed because my home network gives me a very slow connection; The timeout of 10 milli sec is too strict on my home network.

Let me show you what I tried:

I could get my IP address via This worked OK.

That seems to be a Class B ip from the public range, see:

I think is OK, I had doubts only on the value obtained by the OP (34.x.x.x are usually AWS public IP’s, it may make sense only if the test was executed from an AWS VM).

To double check, compare with the value you get by opening the URL in browser (but I think you already did that) or use the Google way or whatever other public web service.

For the local / private IP’s, something like ifconfig | grep "inet " should work to display them on Mac.
To retrieve them by java code, there are some hints in the topic I mentioned previously.

I used to search 's ownership.

The following result revealed the IP Address is from the host ending with

It seems that @bharathi.a ran the code on a VM on Google Compute Engine service, not AWS EC2.

1 Like

Well, then the result they get I think is valid also, for a public IP.
I guess, class A may be preffered by cloud services providers, for a wider broadcast per network compared with class B which apparently is used by most of internet providers.
(this may not be allways true, the IP assigned by my provider is also from class A)

I was tricked by the 34 network which usually I saw it in use by AWS.

E.g if I ping a certain service I maintain (which I know for sure it is hosted in AWS) i get:

$ ping
PING ( 56(84) bytes of data.

Although, the checkip service himself uses two different networks, also from class A:

$ ping
PING ( 56(84) bytes of data.

$ ping
PING ( 56(84) bytes of data.

This is interresting …

For the rest, we can only wait to see what @deepaveerappa.kadrol actually needs, the public one or the local one.

1 Like

Even after using above url,
its displaying the same exception:
url is not supported in this Katalon tool

For trouble shooting, please visit:

09-17-2023 09:22:53 PM Test Cases/ClientUI/Login/Login_Startscreen Device_17_18/Start screen device_setup

Elapsed time: 1.895s

Test Cases/ClientUI/Login/Login_Startscreen Device_17_18/Start screen device_setup FAILED.
at java_net_URL$openStream$ Source)
at Start screen screen device_setup:31)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)

1 Like

did you read the history of this topic carefully an understood what may be the difference between a local ip and a public ip?

why are you trying to login into a service which should only provide you a numeric value?

Hi Bionel,

I am not logging in, I am creating device in my application which needs system IP.
Dynamically i need to pass that Ip to create the device


well, show us the code of this particular testcase you wrote.
i have the feeling you are using the advice provided up to now in a dumb manner.
you cannot use that url directly but wrote a dedicated method to retrieve it and use it further

Yes its described about two types IPs when we ping certain services,