Hi!

I want to write a program that can find all of the IP and Mac addresses and the processes nember connected to a network, fro example an ISP.
for writing this i must know the neccery APIs for finding IP and Mac address.

PLZ help me to start my work. did you know any thing about these APIs or what should i do?

i can program in c# or java.

Recommended Answers

All 11 Replies

Unless you work for the ISP then you are out of luck. The mac address of connected computers can be easily hidden or altered if someone is running a home network:

http://en.wikipedia.org/wiki/Data_Link_Layer

is there a way to find these addresses if they were not altered?

If you are just looking to find IP and MAC address on a network that is easy, but you can't lookup all IP and MAC addresses from an ISP unless you have access to the server(s). There are tons of programs out there that will find all connections to a single IP. Almost all servers have network tools that will show all incoming connections.

If you want to query your DNS for all IP addresses that have names
try this

i=1
while [ i -lt 255 ]; do
nslookup XXX.XX.XX.$i | grep -i name
(( i = i + 1 ))
done

If you want to find all IP addresses currently active on your subnet

# ping XXX.XX.XX.XXX

Yes but what are you really trying to do because it doesn't make sense. You can send traffic at the broadcast address for your subnet then look at your ARP table.

C:\>ping 10.2.5.255

Pinging 10.2.5.255 with 32 bytes of data:


Ping statistics for 10.2.5.255:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\>arp -a

Interface: 10.2.5.215 --- 0x2
  Internet Address      Physical Address      Type
  10.2.5.2              00-xx-xx-d3-xx-13     dynamic
  10.2.5.4              00-xx-xx-6f-xx-ac     dynamic
  10.2.5.5              00-xx-xx-ec-xx-10     dynamic
  10.2.5.10             00-xx-xx-be-xx-17     dynamic
  10.2.5.50             00-xx-xx-34-xx-5c     dynamic
  10.2.5.104            00-xx-xx-c5-xx-5f     dynamic
  10.2.5.212            00-xx-xx-00-xx-70     dynamic
  10.2.5.253            00-xx-xx-06-xx-5d     dynamic

C:\>

Note that 10.2.5.255 is the broadcast address.

I want to write a program (pereferably in c# or java) that can find all IP and mac addresses connected to my subnet when i'm connected to that subnet.

with sending traffic to the network i just can learn some of the addresses not all of them.

thanks alot for your attention. I'm a newbie and already i'm enjoying my membership here!!!!

with sending traffic to the network i just can learn some of the addresses not all of them.

It is up to the individual device connected to the network to transmit its MAC address. Unless you have a managed switch where you can log in and look at the switch's ARP table then you will have to send out traffic to the network and see what responds. You're probably best off to use existing utilities for this.

See:
http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/45cd328e-da44-4cf3-9ee0-5f9d65facfcf/
and
http://groups.google.com/group/DotNetDevelopment/browse_thread/thread/f7d69fec7e56d166

They provided a script:

Code Snippet
@echo off
endlocal
set IPtoCheck=10.0.0.21
ping -n 1 %IPtoCheck% >nul
arp -a | findstr %IPtoCheck%
endlocal

If you had a managed switch then you should automate logging in to the device and downloading the ARP table or possibly querying it with SNMP.

Thanks
Now i can see your point.
what about a LAN? can i find all ip and mac addresses in a LAN? is there a way?

Everything I have discussed thus far was referring to devices on your same network segment (subnet/LAN).

What about this:
we send a broadcast message to the lan that all of the lan must answer:
for example a broad cast the is after the mac address xx-xx-xx-xx-xx-xx ?

There is nothing that says the lan must answer. It is up to the individual workstation. Pinging the broadcast address like in my above post will do the job just fine.

Dear all

I have wrote this program with java for solving this problem, but it just works when there is no security, if some one has some improvemental suggestions, Please share with us

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

/**
 * Created by IntelliJ IDEA.
 * User: masoumeh nourollahi
 */
public class netScanner {
    static byte [] netid=new byte[4];
    static byte [] bcid=new byte[4];
    static List inetAddresses;
    private static String y;
    static String  substring="error";

    public static void main(String[] args) {

          try{
             Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
                  for (NetworkInterface netint : Collections.list(nets))
                           displayInfo(netint);
                           pinging();
       }catch(java.net.SocketException s){
          System.out.print('/');  //
           System.exit(0);
       } catch (IOException e) {
           e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
       }
    }



   static void displayInfo(NetworkInterface netint) throws IOException {

        inetAddresses = netint.getInterfaceAddresses();
        System.out.println("some information a bout my link:");
        System.out.printf("Display name: %s\n", netint.getDisplayName());
        System.out.printf("Name: %s\n", netint.getName());
        System.out.printf("Up? %s\n", netint.isUp());
        System.out.printf("Loopback? %s\n", netint.isLoopback());
        System.out.printf("PointToPoint? %s\n", netint.isPointToPoint());
        System.out.printf("Supports multicast? %s\n", netint.supportsMulticast());
        System.out.printf("Virtual? %s\n", netint.isVirtual());
        System.out.printf("Hardware address: %s\n",Arrays.toString(netint.getHardwareAddress()));
        System.out.printf("MTU: %s\n", netint.getMTU());
        System.out.printf("\n");
        System.out.println("my ip address is: "+((InterfaceAddress)inetAddresses.get(0)).getAddress());
        System.out.println("the sunnetmask address is: "+((InterfaceAddress)inetAddresses.get(0)).getNetworkPrefixLength());
        System.out.println("the broadcast address of this subnet is:"+bcid);
        }
    static void pinging() throws IOException {

           Socket mySocket;

           if(!inetAddresses.isEmpty()){
           bcid =((InterfaceAddress)inetAddresses.get(0)).getBroadcast().getAddress(); //gets the last ip address in subnet

           netaddress(
                   ((InterfaceAddress)inetAddresses.get(0)).getNetworkPrefixLength(),  //creats the mask field
                   ((InterfaceAddress)inetAddresses.get(0)).getAddress().getAddress()  //creats the myip field
           );
           byte [] pingip=netid;
           for(;;){
           InetAddress ping =InetAddress.getByAddress(pingip);
        //   boolean reachable=ping.isReachable(5000);     // This command is doing the same work as the ping command in windows
           try{
               Process ps = Runtime.getRuntime().exec("ping.exe " + ping);
                                         BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
                                         StringBuilder sb = new StringBuilder();
                                         String line;
                                         while ((line = br.readLine()) != null) {
                                             sb.append(line);
                                             sb.append("\n");
                                         }
                                   y= sb.toString();
                                         System.out.print(sb.toString());

                                     } catch (IOException e) {
                                         e.printStackTrace();
                                     }


           if(!contains(y,substring)){
               System.out.println("The ip address "+ping+"is reachable");
               for(int port =0;port<65536;port++){
                   try{
                       mySocket=new Socket(ping,port);
                       System.out.println("The port"+port +"on ip:"+ ping + "is free.");
                       mySocket.close();
                   }catch(IOException c){
                       System.out.println("The port"+port +"on ip:"+ ping + "is closed.");
                   }
               }
           }
          else
               System.out.println("The pinged ip addres is unreachable, probably it is not up in your subnet");
            pingip[3]++;
            if(pingip[3]==(byte)255)
               pingip[2]++;
            if(pingip[2]==(byte)255)         //here we ping ips in our subnet from the first ip address to the last one
               pingip[1]++;
            if(pingip[1]==(byte)255)
               pingip[0]++;
            if(pingip[0]==(byte)127)        //beacuase the ip addresses that are not in class A have at least 2 bytes of net ids
            break;
            if(pingip[0]==bcid[0] & pingip[1]==bcid[1] & pingip[2]==bcid[2] & pingip[3]==bcid[3])
            break;
           }
       }
           else
               System.out.println("null pointer exception");
       }




    static void netaddress(short masklength,byte[] sysip)// throws IOException
         {
            int k=masklength;
            String ipstring="";

            int ip1=sysip[0];
            int ip2=sysip[1];
            int ip3=sysip[2];
            int ip4=sysip[3];
            int j=8;

             for(int i=0;i<32;i++){
                 if (j==0) {
                 ipstring+=".";
                 j=8;
                 }
                 if(k>0){
                     ipstring+="1";
                     k--;
                 }
                 else ipstring+="0";
                 j--;
             }

                int firstpart,secondpart,thirdpart;
                firstpart=ipstring.indexOf('.');
                netid[0]=(byte)(ip1& Integer.valueOf((ipstring.substring(0,firstpart)),10));
                ipstring=ipstring.substring((firstpart+1));
                secondpart=ipstring.indexOf('.');
                netid[1]=(byte)(ip2& Integer.valueOf((ipstring.substring(0,secondpart)),10));
                ipstring=ipstring.substring((secondpart+1));
                thirdpart=ipstring.indexOf('.');
                netid[2]=(byte)(ip3& Integer.valueOf((ipstring.substring(0,thirdpart)),10));
                netid[3]=(byte)(ip4& Integer.valueOf((ipstring.substring(thirdpart+1)),10));

                 System.out.println("The first ip address in this subnet is:"+ipstring);
        }
        public static boolean contains(String y, String substring) {

    if(y.indexOf(substring) != -1)
   return true;

    else { return false; }
        }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.