0% found this document useful (0 votes)
430 views

Mac and Ip Address Java

This document describes how to get the MAC and IP address of a network interface card (NIC) using Java. It begins with definitions of MAC and IP addresses, explaining that MAC addresses are unique hardware identifiers while IP addresses specify network locations. The code sample shows a graphical Java interface with buttons to display either the local host IP address or MAC address when clicked. It retrieves this information using InetAddress and NetworkInterface classes.

Uploaded by

xcms
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
430 views

Mac and Ip Address Java

This document describes how to get the MAC and IP address of a network interface card (NIC) using Java. It begins with definitions of MAC and IP addresses, explaining that MAC addresses are unique hardware identifiers while IP addresses specify network locations. The code sample shows a graphical Java interface with buttons to display either the local host IP address or MAC address when clicked. It retrieves this information using InetAddress and NetworkInterface classes.

Uploaded by

xcms
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

HOW TO GET MAC AND IP ADDRESS OF A NIC

1 1 1 1
Alanís García Teresa, Cruz Cruz Laura, Martínez Solano Cristhian, Montoya
1 1 1
García Oscar, Sánchez Ávila José Carlos, Yessenia Sánchez Torres, Serrano
1
Avelino Pascual Jesús, Pérez Alva Iliana,
1
Tecnológico de Estudios Superiores de Jocotitlán
Carretera Toluca-Atlacomulco, km. 44.8 Ejido de San Juan y San Agustín CP. 50700,
Jocotitlán México

Abstract. NIC is a computer hardware component designed to allow


computers to communicate over a computer network. It is both an OSI
layer 1 (physical layer) and layer 2 (data link layer) device, as it
provides physical access to a networking medium and provides a low-
level addressing system through the use of MAC addresses. It allows
users to connect to each other either by using cables or wirelessly. In
this project we describe how we can get the MAC and IP address of a
NIC, using Java as a programming language.

Resumen. La NIC es un componente de hardware informático diseñado


para permitir a las computadoras comunicarse a través de una red
informática. Es a la vez una capa de OSI 1 (capa física) y la capa 2
(capa de enlace de datos) del dispositivo, ya que proporciona acceso
físico a un soporte de red y proporciona un bajo nivel de sistema de
direccionamiento a través de la utilización de las direcciones MAC.
Permite a los usuarios conectarse entre sí, ya sea con cables o
inalámbrica. En este proyecto se describe la forma en que puede obtener
las direcciones MAC e IP de una tarjeta de red, utilizando Java como
lenguaje de programación.
INTRODUCTION

This article talks about of how get the address MAC (Media Address
Control) and IP (Internet protocol) of a NIC with a graphic interface
made in Java.

The interface has 2 buttons where the user can chose the option likes
him and the program can get the address.

The program was made with the tools that the program’s language
brings

Also it describes what is address MAC and IP, for what use them, and
the important into a red, so how the formats that trey have.

Whereas MAC addressing works


MAC ADDRESS at the data link layer, IP
addressing functions at the
The MAC address is a unique network layer (layer 3). It's a slight
value associated with a network oversimplification, but one can
adapter. MAC addresses are also think of IP addressing as
known as hardware addresses or supporting the software
physical addresses. They uniquely implementation and MAC
identify an adapter on a LAN. addresses as supporting the
MAC addresses are 12-digit hardware implementation of the
hexadecimal numbers (48 bits in network stack.
length). By convention, MAC
addresses are usually written in The MAC address generally
one of the following two formats: remains fixed and follows the
network device, but the IP address
MM:MM:MM:SS:SS:SS changes as the network device
moves from one network to
The first half of a MAC address another.
contains the ID number of the
adapter manufacturer. These IDs
are regulated by an Internet IP ADDRESS
standards body (see sidebar). The
second half of a MAC address An Internet Protocol (IP) address
represents the serial number is a numerical label that is
assigned to the adapter by the assigned to devices participating in
manufacturer. In the example: a computer network that uses the
Internet Protocol for
00:A0:C9:14:C8:29 communication between its nodes.
An IP address serves two principal
The prefix 00A0C9 indicates the functions: host or network
manufacturer is Intel Corporation. interface identification and
location addressing. Its role has
been characterized as follows: "A
name indicates what we seek. An
address indicates where it is. A
route indicates how to get there.
contenedor.setLayout(new
IP addresses specify the locations FlowLayout());
of the source and destination contenedor.add(e1);
nodes in the topology of the contenedor.add(b1);
routing system. For this purpose, contenedor.add(b2);
some of the bits in an IP address
setVisible(true);
are used to designate a setSize(300,200);
subnetwork. The number of these }
bits is indicated in CIDR notation, public static void main(String args[]){
appended to the IP address; e.g., dir aplicacion=new dir();
208.77.188.166/24. aplicacion.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
CODE }
private class botones implements
import javax.swing.*; ActionListener{
import java.awt.*; public void
import java.net.*; actionPerformed(ActionEvent evento)
import java.awt.event.*; {
if(evento.getSource()==b1){
try {
public class dir extends JFrame{ //InetAddress address =
private JLabel e1,e2,e3; InetAddress.getByName( "" );
private JButton b1,b2;
public InetAddress address; address = InetAddress.getLocalHost();
System.out.println( address );
public dir() System.out.println();
{ JOptionPane.showMessageDialog(null
super("DIRECCIONES"); ,""+address);
e1=new JLabel("ELIJA LA }
DIRECCION QUE DESEA OBTENER"); catch( UnknownHostException e ) {
b1=new JButton ("DIR IP"); System.out.println( e );
b2=new JButton ("DIR MAC") ; JOptionPane.showMessageDialog(null
,"DEBE ESTAR CONECTADO A UNA
botones manejador=new botones(); RED");
b1.addActionListener(manejador); }
b2.addActionListener(manejador); //String dirIPLocal =
java.net.InetAddress.getLocalHost().toStri
ng();
Container
contenedor=getContentPane(); }
else if(evento.getSource()==b2){ /JOptionPane.showMessageDialog("%02
try { X%s", dirMac[k], (k < dirMac.length -
InetAddress addr = 1) ? "-" : "");
InetAddress.getLocalHost();
NetworkInterface dir1 = //JOptionPane.showMessageDialo
NetworkInterface.getByInetAddress(addr) g(null,"EN CONSTRUCCION"); }
; } catch (UnknownHostException e) {
byte[] dirMac = e.printStackTrace();
dir1.getHardwareAddress(); } catch (SocketException e) {
e.printStackTrace();
System.out.println(dirMac); }
System.out.println(dirMac.length); }
for (int k = 0; k < dirMac.length; k+ }
+) { }
System.out.format("%02X%s", }
dirMac[k], (k < dirMac.length - 1) ? "-" :
"");
References

[1]COMO PROGRAMAR EN JAVA


DEITEL AND DEITEL
ED PEARSON EDUCACION

[2]GUIA DEL PRIMER AÑO CCNA 1 Y2


3ª EDICION
ED CISCO

[3]GUIA Y PROTOLOS DE ENRUTAMIENTO


JOHNSON ALLAN
ED TRILLAS

You might also like