Questions tagged [inetaddress]
227 questions
108
votes
12 answers
Why does InetAddress.isReachable return false, when I can ping the IP address?
InetAddress byName = InetAddress.getByName("173.39.161.140");
System.out.println(byName);
System.out.println(byName.isReachable(1000));
Why does isReachable return false? I can ping the IP.

jiafu
- 6,338
- 12
- 49
- 73
98
votes
2 answers
Java: Convert a String (representing an IP) to InetAddress
Possible Duplicate:
Is there an easy way to convert String to Inetaddress in Java?
I'm trying to convert a string(representing an IP address, e.g. 10.0.2.50) into an InetAddress obj.
According to the API it is possible to create an Object…

rob
- 2,904
- 5
- 25
- 38
45
votes
2 answers
Get IP address with URL string? (Java)
In my program a user enters a url string, say
http://www.engineering.uiowa.edu/~hawkeng//fall01/graphics/potato.gif
how would I get the IP address of this url? I tried using
InetAddress address = InetAddress.getByName(urlStr);
but the result…

user1205853
- 651
- 2
- 8
- 14
39
votes
1 answer
Host Name Vs Canonical Host Name
Can anyone please explain me the difference between Host Name and Canonical Host Name?
I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs.
So I am just wondering, which one I should opt for?

Aryan
- 1,767
- 2
- 22
- 39
31
votes
5 answers
Is there an easy way to convert String to Inetaddress in Java?
I am trying to convert strings into Inetaddress. I am not trying to resolve hostnames: the strings are ipv4 addresses. Does InetAddress.getByName(String host) work? Or do I have to manually parse it?

TiansHUo
- 8,509
- 7
- 45
- 57
31
votes
10 answers
Java: convert int to InetAddress
I have an int which contains an IP address in network byte order, which I would like to convert to an InetAddress object. I see that there is an InetAddress constructor that takes a byte[], is it necessary to convert the int to a byte[] first, or…

kdt
- 27,905
- 33
- 92
- 139
15
votes
2 answers
Getting My LAN ip address (192.168.xxxx) (IPV4)
In my android device I am trying to find its IP address(IPV4).
If I do the following code
InetAddress inet = InetAddress.getLocalHost();
System.out.println(inet.getHostAddress()); //giving me 127.0.0.1
The code is giving me 127.0.0.1.
I wanted to…

Vishnudev K
- 2,874
- 3
- 27
- 42
14
votes
4 answers
DNS query in Java
I am messing around with DNS services in Java. I am specifically trying to look up all google.com addresses and display them in an array, similar to running a lookup using nslookup:
nslookup -q=TXT _netblocks.google.com 8.8.8.8
I am using…

zJK
- 141
- 1
- 1
- 3
12
votes
2 answers
How to store both IPv4 or IPv6 in single column in SQL Server?
Should I use binary(16) or varbinary(16)?
I know I can use getAddress() in java.net.InetAddress (Java) or System.Net.IPAddress (C#) to get a byte[] representation of both IPv4 and IPv6, but if I need to insert IPv4 i.e. binary(4) into a binary(16)…

Henry
- 32,689
- 19
- 120
- 221
12
votes
1 answer
How can I bind serversocket to specific IP?
If I have a String representing an IP address (IPv4 or IPv6) how can I create a ServerSocket and bind to this IP without caring if the IP passed in, is IPv4 or IPv6?
I see that there is a constructor:ServerSocket(int port, int backlog, InetAddress…

Jim
- 18,826
- 34
- 135
- 254
10
votes
1 answer
Java Getting IPv4 Address
Regarding this link where using the codes provided to produce the IP addresses.
String ip;
try {
Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
…

Fouzy
- 125
- 1
- 1
- 7
9
votes
1 answer
JAVA Specifying port with InetAddress
I am using InetAddress to determine if my server is online.
If the server is offline it will restart the server.
This process loops every 5 minutes to check once again if the server is online.
It works fine but now I need to figure out how to…

Cloudnine1999
- 93
- 1
- 1
- 5
8
votes
1 answer
Java InetAddress.isReachable() timeout
I am trying to find out if specific hosts on my network are reachable.
My java code is as follows:
InetAddress adr = InetAddress.getByName(host);
if(adr.isReachable(3000)){
System.out.println(host + " is reachable");
}
This works quite well,…

Jerome
- 275
- 2
- 7
8
votes
3 answers
Increment IP address
In that program I want to increment IP address. And I see output like that:
125.23.45.67
126.23.45.67
127.23.45.67
128.23.45.67
129.23.45.67
130.23.45.67
131.23.45.67
132.23.45.67
133.23.45.67
134.23.45.67
But I want to see output like…

d_pilot
- 309
- 1
- 3
- 12
7
votes
3 answers
Obtain FQDN in Java
I am trying to obtain the FQDN of a windows machine in my domain, using Java code.
I have tried the InetAddress.getByName("machine-1").getCanonicalHostName() but only returns the machine name.
On the other hand if I ping "machine-1" I get the fully…

hgonzalez
- 81
- 1
- 3