Questions tagged [inetaddress]

227 questions
4
votes
2 answers

How do I access the Connection-specific DNS Suffix for each NetworkInterface in Java?

Is it possible within a Java program to access the string contained in the "Connection-specific DNS Suffix" field of a Windows machine's ipconfig /all output? Eg: C:>ipconfig /all Ethernet adapter Local Area Connection: Connection-specific DNS…
arjunaw
  • 101
  • 1
  • 5
4
votes
4 answers

How can I check if a String is IPv4 / IPv6 or domain name? (Java)

How can I check if a string matches a IPv4, IPv6 adress or a domain name like www.google.com? I found this for IPv4: Validating IPv4 string in Java And the same kind of system works for IPv6 but how can I check domain names? EDIT: To clarify: I want…
F_Schmidt
  • 902
  • 1
  • 11
  • 32
4
votes
2 answers

InetAddress getLocalHost() does not return expected IP address from C:\WINDOWS\system32\drivers\etc\hosts

In the file C:\WINDOWS\system32\drivers\etc\hosts I have only the following line 192.168.0.23 computername.domain.com computername When I run InetAddress localhost = InetAddress.getLocalHost(); System.out.println("getLocalHost:" +…
Lars Andren
  • 8,601
  • 7
  • 41
  • 56
4
votes
1 answer

Find IP of program trying to connect to ServerSocket

Although I searched about it I couldn't find an answer. Let's say I have the following Java code: ServerSocket serve = null; try { server = new ServerSocket(5567); } catch (IOException e) { System.err.println("Problem…
Navorkos
  • 43
  • 1
  • 3
4
votes
0 answers

Unable to get Hostname (Computer name) using InetAddress in android

i am working on one module to scan local network and Ip, Mac, Hostname and other details of other devices connected through the same network. i am unable to get Host PC name from InetAddress class in android. Please check my below code: String…
Rl.Android
  • 41
  • 6
4
votes
2 answers

InetAddress java 8 is not getting the hostname

InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the…
Mohamed Taboubi
  • 6,663
  • 11
  • 55
  • 87
4
votes
3 answers

How to turn Java class into one of its subclasses (SocketAddress and InetSocketAddress)

I am trying to get the IP of a socket connection in string form. I am using a framework, which returns the SocketAddress of the received message. How can i transform it to InetSocketAddress or InetAddress?
vasion
  • 1,237
  • 3
  • 18
  • 29
3
votes
1 answer

How to get the DNS resolution time without using the class InetAddress or avoiding the 10 min cached time?

I've been trying to get the DNS resolution time using the next code: val url = URL(dataExperienceTestResult.pingUrl) val host: String = url.host val currentTime: Long = SystemClock.elapsedRealtime() val address: InetAddress =…
CPI
  • 786
  • 1
  • 5
  • 18
3
votes
0 answers

InetAddress.getAllByName() BLOCKED

I encountered a wired question recently. I have an android device which connected the wifi, I'm sure the wifi is fine. but the android device can't access the internet. Then I found something wrong with the DNS resolution, here is what I did. 1. I…
Will Tang
  • 975
  • 1
  • 7
  • 17
3
votes
2 answers

InetAddress.getAddress() always returns a null, but somehow still works

I have a String IP address that I need to convert to a byte array. For this, I used InetAddress.getByName(ip).getAddress(), and it all works great. However, when I looked at the code of InetAddress.getAddress(), it looks like this: public byte[]…
a3y3
  • 1,025
  • 2
  • 10
  • 34
3
votes
0 answers

InetAddress.getHostName() does not return expected reverse name lookup from remote IP, like linux Host command

I have a simple java program that will print the dns name of IP address. package p1; import java.net.InetAddress; public class Main { public static void main(String[] args) throws Exception { …
cgean
  • 31
  • 2
3
votes
1 answer

a funny thing happens... ExecutorCompletionService

I have an application written in java that needs to find all the reachable hosts on the network. I use InetAddress.isReachable() to do this with a timeout of 2000 milliseconds. I look up the current local machine's IP address and based on that I…
Hector
  • 4,016
  • 21
  • 112
  • 211
3
votes
1 answer

Why does Java InetAddress.isReachable() not work on JRE 1.8.x like on JRE 1.7.x

I've written a programm a year ago and today I saw that this programm give me some curious output. One kind to detect PC's or notebooks in our network I'm using the InetAddress class. My programm works how it should, until Java 1.8.x runs on the…
prototype0815
  • 592
  • 2
  • 7
  • 24
3
votes
2 answers

Why is Java's InetAddress getHostName() not giving me the host's name?

I'm trying to get the device's name using its local IP address on the network. Is this how I'm supposed to do it? ex) Arnold-PC, andoid-nnnnnnnnnn String name = InetAddress.getByName(ip).getHostName(); System.out.println(name); The above should…
God Usopp
  • 331
  • 1
  • 6
  • 18
3
votes
1 answer

ipv4/ipv6 network address match in node-js

I am looking for something like python's netaddr.IPNetwork in node.js. Basically, i have IP network addresses like 1.1.1.1/30, 1::/128 and want to validate in the backend in express if the data provided by user is valid ip network? Thanks,
amulllb
  • 3,036
  • 7
  • 50
  • 87
1 2
3
15 16