GETTING THE IP, MAC AND NAME OF A LAN DEVICES

undefined

undefined undefined1 I.S.C. Juan Alberto Antonio Velázquez undefined undefined1Alanís García Teresa, 1Cruz Cruz Laura, 1 Martínez Solano Cristhian, 1 Montoya García Oscar, 1 Sánchez Ávila José Carlos, 1 Yessenia Sánchez Torres, 1 Serrano Avelino Pascual Jesús, 1 Pérez Alva Iliana, undefined undefined

undefined undefined1 Tecnológico de Estudios Superiores de Jocotitlán undefined undefinedCarretera Toluca-Atlacomulco, km. 44.8 Ejido de San Juan y San Agustín CP. 50700, Jocotitlán México

Abstract. The MAC, IP address and network name are network Ids, which allow proper communication of computers in a network. The IP address identifies a logical and hierarchical, to an interface of a device within a network using IP protocol. The MAC (Media Access Control) is a 48-bit identifier that uniquely corresponds to an Ethernet network, also known as the physical address. This project describes how to obtain these addresses and the names of network devices, also are described the state of the TCP, ICMP and UDP protocols of the computer where is running the application.

Resumen. La dirección MAC, dirección IP y el nombre de red son identificadores de red, que permiten la comunicación correcta de las computadoras en una red. La dirección IP identifica, de manera lógica y jerárquica, a una interfaz de un dispositivo dentro de una red que utilice el protocolo IP. La dirección MAC (control de acceso al medio) es un identificador de 48 bits que corresponde de forma única a una Ethernet de red, conocida también como la dirección física. En este proyecto se describe como obtener estas direcciones así como el nombre de los dispositivos de red, también se describen el estado de los protocolos TCP, ICMP y UDP del ordenar donde se ejecuta la aplicación.

INTRODUCTION

This article talks about how get the address MAC and the IP (Internet protocol) of LAN devices, it shows too the hostname of every one of the devices.

This small application tries to capture the status of some network protocols, like IP, TCP, ICMP and UDP.

The program was developed using some commands which are nast and netstat and implemented in java. These commands provide us the necessary information to obtain the requirements which we describe in this article.

MAC ADDRESS

The MAC address is a unique value associated with a network adapter. MAC addresses are also known as hardware addresses or physical addresses. They uniquely identify an adapter on a LAN.

MAC addresses are 12-digit hexadecimal numbers (48 bits in length). By convention, MAC addresses are usually written in one of the following two formats:

MM:MM:MM:SS:SS:SS

The first half of a MAC address contains the ID number of the adapter manufacturer. These IDs are regulated by an Internet standards body (see sidebar). The second half of a MAC address represents the serial number assigned to the adapter by the manufacturer. In the example:

00:A0:C9:14:C8:29

The prefix 00A0C9 indicates the manufacturer is Intel Corporation.

Whereas MAC addressing works at the data link layer, IP addressing functions at the network layer (layer 3). It's a slight oversimplification, but one can think of IP addressing as supporting the software implementation and MAC addresses as supporting the hardware implementation of the network stack.

IP ADDRESS

An Internet Protocol (IP) address is a numerical label that is assigned to devices participating in a computer network that uses the Internet Protocol for communication between its nodes. An IP address serves two principal functions: host or network 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.

IP addresses specify the locations of the source and destination nodes in the topology of the routing system. For this purpose, some of the bits in an IP address are used to designate a subnetwork. The number of these bits is indicated in CIDR notation, appended to the IP address; e.g., 208.77.188.166/24.

NAST

The Network Analyzer Sniffer Tool or nast is a packet capturing program that displays the captured information in various ways depending on the command line options you specify.

IP

Network layer protocol in the TCP/IP stack offering a connectionless internetworking service. IP provides features for addressing, type-of-service specification, fragmentation and reassembly and security.

TRANSMISSION CONTROL PROTOCOL (TCP)

TCP is the protocol used as the basis of most internet services. It is used in conjuction with the internet protocol (IP). It allows for reliable communication, ensuring that packets reach their intended destinations

INTERNET CONTROL MESSAGING PROTOCOL (ICMP)

Internet messaging protocol. Network layer internet protocol that reports errors and provides other information relevant to IP packet processing.

USER DATAGRAM PROTOCOL (UDP)

A connectionless transport layer protocol in the transmission Control Protocol/Internet Protocol (TCP/IP) stack. UDP is a simple protocol that exchanges datagrams without acknowledgments or guaranteed delivery, and requires that error processing and retransmission be handle by other protocols.

CODE

package redes;

import java.io.*;

import java.util.*;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.*;

import java.net.*;

public class Caddress extends JFrame {

String SRes="“,SAux=”";

int IAux=0;

InetAddress IAddress;

boolean BEstado=false;

private void initComponents() {

LTitulo = new javax.swing.JLabel();

BObtener = new javax.swing.JButton();

BSalir = new javax.swing.JButton();

jScrollPane1 = new javax.swing.JScrollPane();

TARes = new javax.swing.JTextArea();

LNombre = new javax.swing.JLabel();

LDireccion = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setBackground(new java.awt.Color(51, 102, 255));

LTitulo.setFont(new java.awt.Font(“Comic Sans MS”, 1, 18));

LTitulo.setText(“DIRECCIONES IP”);

BObtener.setText(“OBTENER”);

BObtener.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BObtenerActionPerformed(evt);

}

});

BSalir.setText(“SALIR”);

BSalir.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BSalirActionPerformed(evt);

}

});

TARes.setColumns(20);

TARes.setRows(5);

jScrollPane1.setViewportView(TARes);

LNombre.setFont(new java.awt.Font(“Comic Sans MS”, 1, 12));

LNombre.setText(“MAC”);

LDireccion.setFont(new java.awt.Font(“Comic Sans MS”, 1, 12));

LDireccion.setText(“IP NOMBRE”);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(20, 20, 20)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()

.addComponent(BObtener, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)

.addComponent(BSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(23, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

.addGap(21, 21, 21)

.addComponent(LNombre)

.addGap(130, 130, 130)

.addComponent(LDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGap(43, 43, 43))

.addGroup(layout.createSequentialGroup()

.addGap(66, 66, 66)

.addComponent(LTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(91, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(16, 16, 16)

.addComponent(LTitulo)

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(LNombre)

.addComponent(LDireccion))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(BObtener)

.addComponent(BSalir))

.addGap(12, 12, 12))

);

pack();

}// </editor-fold>//GEN-END:initComponents

private void BObtenerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BObtenerActionPerformed

// TODO add your handling code here:

Process proc=null;

try {

proc = Runtime.getRuntime().exec(“nast -m”);

}

catch (IOException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

InputStream is=proc.getInputStream();

int size;

String s;

try {

int exCode = proc.waitFor();

}

catch (InterruptedException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

StringBuffer ret=new StringBuffer();

try {

while ((size = is.available()) != 0) {

byte[] b = new byte[size];

is.read(b);

s = new String(b);

ret.append(s);

}

} catch (IOException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

//protocolos

Process proc2=null;

try {

proc2 = Runtime.getRuntime().exec(“netstat -s”);

}

catch (IOException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

InputStream is2=proc2.getInputStream();

try {

int exCode = proc2.waitFor();

}

catch (InterruptedException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

StringBuffer ret2=new StringBuffer();

size=0;

s="";

try {

while ((size = is2.available()) != 0) {

byte[] b = new byte[size];

is2.read(b);

s = new String(b);

ret2.append(s);

}

} catch (IOException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}

int Ipos=ret.indexOf(“=”);

ret.delete(0, Ipos+60);

Ipos=ret.indexOf(“This”);

ret.delete(Ipos-4,ret.length());

while(ret.indexOf(“(”) > 0 && ret.indexOf(“)”) > 0)

{

ret.delete(ret.indexOf(“(”),ret.indexOf(“)”)+1);

//ret.insert(ret.indexOf(“)”),“ ”);

}

try

{

String SAux=ret.toString();

String SDir[]=SAux.split(“\\s+”);

String Aux="";

for(int x=1;x<SDir.length;x=x+2)

{

System.out.println(SDir[x]+“>\n”);

Aux+=SDir[x-1]+“\t”+SDir[x]+“\t ”;

InetAddress IAddress = InetAddress.getByName(SDir[x]);

Aux+=IAddress.getHostName()+“\n”;

}

TARes.setText(“\n”+Aux+“\n”+ret2.toString());

}catch(Exception e){}

}//GEN-LAST:event_BObtenerActionPerformed

private void BSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BSalirActionPerformed

System.exit(0); // TODO add your handling code here:

}//GEN-LAST:event_BSalirActionPerformed

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Caddress().setVisible(true);

}

});

}

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JButton BObtener;

private javax.swing.JButton BSalir;

private javax.swing.JLabel LDireccion;

private javax.swing.JLabel LNombre;

private javax.swing.JLabel LTitulo;

private javax.swing.JTextArea TARes;

private javax.swing.JScrollPane jScrollPane1;

// End of variables declaration//GEN-END:variables

}

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

Comentarios