I can't find the ip address of a device connected to my network. I tried using network interface, but only gives me the loopback address and my pc address; the code that i used is:
try
{
Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces();
for (; n.hasMoreElements();)
{
NetworkInterface e = n.nextElement();
System.out.println("Interface: " + e.getName());
Enumeration<InetAddress> a = e.getInetAddresses();
for (; a.hasMoreElements();)
{
InetAddress addr = a.nextElement();
System.out.println(" " + addr.getHostAddress());
}
}
}catch (Exception e)
{
System.out.println(e.toString());
}
Also, i used PrintServiceLookup,but the methods of that class doesn't give the ip address (the device is a card printer); the code that i used is:
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
System.out.println("Printer Services found:");
printService(services);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
if (service!=null) {
System.out.println("Default Printer Service found:");
System.out.println(service);
}
private static void printService(PrintService[] services) {
if (services!=null && services.length>0) {
for (int i = 0; i < services.length; i++) {
System.out.println(services[i]);
}
}
}
Anyone has a different point of view or perspective to solve the issue?