how to get an lan system ip and mac address in java code

Ads
 

how to get an lan system ip and mac address in java code

strong text

View Answers

January 12, 2012 at 5:15 PM

Java get system IP Address:

import java.net.*;
import java.io.*;

public class GetIPAddress {
public static void main(String [] args) {
try {
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
}
}

January 12, 2012 at 5:24 PM

Java get Mac Address:

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

public class MacAdd {

    public static void main(String[] args) {
        try {

            InetAddress add = InetAddress.getByName("192.168.20.53");


            NetworkInterface ni1 = NetworkInterface.getByInetAddress(add);
            if (ni != null) {
                byte[] mac1 = ni1.getHardwareAddress();
                if (mac1 != null) {

                    for (int k = 0; k < mac.length; k++) {
                        System.out.format("%02X%s", mac[k], (i < mac.length - 1) ? "-" : "");
                    }
                } else {
                    System.out.println("Address doesn't exist ");
                }
            } else {
                System.out.println("address is not found.");
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
}

Ads









Related Tutorials/Questions & Answers:
how to get an lan system ip and mac address in java code
how to get an lan system ip and mac address in java code  strong text
Get IP Address in Java
Get IP Address in Java In this example we will describe How to get ip address in java. An IP address is a numeric unique recognition number which...(). getHostAddress(). InetAddress():-The InetAddress is class represents an IP address
Advertisements
Getting IP address of All the machines
Getting IP address of All the machines  Program how to fetch All the IP address on my domain(LAN) in java
How to find MAC(Hardware address) address of access point
How to find MAC(Hardware address) address of access point  How can i find out MAC address of Access Point using java
Find Exact Location from IP address in java?
Find Exact Location from IP address in java?  I am looking for API where we can pass IP address and get the location (Cityname,Country name). please suggest any API OR sample code. Thank you
Java Get Example
in the network for communication. To get IP address of our own system in a java... Get examples like how to get the date and time, IP Address or memory size etc... practice   IP Address:  This Java Get IP Address
Getting IP Address
Getting IP Address  Hi... i want to get the ip address of the current... get the ip address 247 in database but i need to get the ip address of that particular system.... how to get that please help me doing that... thank
Getting IP Address
Getting IP Address  Hi... i want to get the ip address of the current... get the ip address 247 in database but i need to get the ip address of that particular system.... how to get that please help me doing that... thank
Java get System Locale
Java get System Locale       In this section, you will learn how to obtain the locale. We... of the system. Here is the code of GetSystemLocale.java class 
How can I find my DHCP IP address on my computer?
How can I find my DHCP IP address on my computer?  Hi, I am using.... How to find the IP address? Thanks   Hi, You can try following command? Here is the command to get the IP address: cat $(ps aux | grep -o '[/]var
uploading a file at another system in lan using jsp
uploading a file at another system in lan using jsp  Thanks...". It is working when i gave address of the local system to savefile But if i want to save or upload the file at another system in lan at location "http
Get GMT from IP
Get GMT from IP  How do I get GMT value from IP address?? Thanx in Adv
How to get system current cursor type
How to get system current cursor type  In Windows how can i get the current mouse/keyboard cursor type like 'text cursor' from my java application
Find Your Host Name/IP Address
, In which the host name of the local system is Comp20 and the IP address... Ipaddress.java C:\roseindia>java Ipaddress Local IP Address... Find Your Host Name/IP Address   
IP Address validation
IP Address validation  hi,I m now working with my final yr project,nd stuck in th middle i don't know how to validate the IP address in a JText field...(ie) the user shld enter the IP address in JTxt and when he hit the 'Submit
FTPClient : Get System Type
This section explain how to get system type by using method of FTPClient class in java
Visitor IP Address and Host Name using jsp
Visitor IP Address and Host Name using jsp  I have created one jsp page and i want to display the ip address of the visitor in my page. I used the following code to get the ip address: String ip=request.getRemoteAddr(); But i am
How to get Java SDK
How to get Java SDK  Hi, I have purchased a new computer and installed windows 7. Now I have to get the Java SDK and install on my computer for developing and testing Java programs. So, can anyone tell me How to get Java SDK
ModuleNotFoundError: No module named 'ip-address'
'ip-address' How to remove the ModuleNotFoundError: No module named 'ip...ModuleNotFoundError: No module named 'ip-address'  Hi, My Python... have to install padas library. You can install ip-address python
ModuleNotFoundError: No module named 'ip-address'
'ip-address' How to remove the ModuleNotFoundError: No module named 'ip...ModuleNotFoundError: No module named 'ip-address'  Hi, My Python... have to install padas library. You can install ip-address python
How to get current timestamps in Java
How to get current timestamps in Java  Hi, I want to get the current Timestamp in Java and then use it in JDBC program. How to get current timestamps in Java? Thanks   Hi, In Java using get the current Timestamp
Collect Mac Address Connected via Bluetooth
Collect Mac Address Connected via Bluetooth  How to collect automatically all mac address connected via bluetooth and save in a file
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data to mysql using setter and getter method by using java pelease let me have the code
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data to mysql using setter and getter method by using java pelease let me have the code
How To Unblock IP address from command line in CSF Firewall ââ?¬â?? Linux Server?
How To Unblock IP address from command line in CSF Firewall ΓΆβ?¬β?? Linux Server?  Hi, How To Unblock IP address from command line in CSF Firewall... the ip and then restart the csf server using following command: csf -r
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java and trying to write a program to get the current date. How to get the current date in Java? Thanks   Hi, Check the tutorial: Java program to get current date
ModuleNotFoundError: No module named 'get-mac'
-mac' How to remove the ModuleNotFoundError: No module named 'get-mac...ModuleNotFoundError: No module named 'get-mac'  Hi, My Python... to install padas library. You can install get-mac python with following command
ModuleNotFoundError: No module named 'get-mac'
-mac' How to remove the ModuleNotFoundError: No module named 'get-mac...ModuleNotFoundError: No module named 'get-mac'  Hi, My Python... to install padas library. You can install get-mac python with following command
how to get this xml syntx in java??????
how to get this xml syntx in java??????  how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
how to get this xml syntx in java??????
how to get this xml syntx in java??????   how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
Overview of Networking through JAVA,Find the Host name in reverse of given IP address
Find the Host name in reverse of given IP address... and create a class object and pass the IP address in InetAddress.getByName() method. Now retrieve the Host name of the IP address what we are pass in getByName

Ads