Get all the IP Addresses to Which a Device is Exposed

Get all the IP Addresses to Which a Device is Exposed

At times, your device can be exposed using multiple interface cards. The following code sample will help identify various interfaces and the related IP configuration available on them.

import java.net.*;import java.util.*;public class NetworkInterfaceIPs {   public static void main(String args[])   {      NetworkInterfaceIPs networkInterfaceIPs = new NetworkInterfaceIPs();      networkInterfaceIPs.proceed();   }   private void proceed()    {      try      {         Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();         InetAddress inetAddress = null;         System.out.println("Available IPs in NetworkInterface.");         while (networkInterfaces.hasMoreElements()) {                NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();                Enumeration inetAddresses = networkInterface.getInetAddresses();                            while (inetAddresses.hasMoreElements()) {                    inetAddress = inetAddresses.nextElement();                    if (inetAddress instanceof Inet4Address) { //Working on only IPv4 IPs                  System.out.println("IP: " + inetAddress.getHostAddress());                    }                               }            }               }catch(SocketException se)      {         System.out.println("SocketException: " + se);      }   }}/*

Expected output:

[[email protected]]# java NetworkInterfaceIPsAvailable IPs in NetworkInterface.IP: 127.0.0.1IP: 134.220.154.89*/ 
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved