Network Discovery tool

G

Guest

hi all

I would like to write a network discovery tool, that will go through a given ip range and see what devices are connected to the network. I would also liek to be able to get the MAC address' of the devices attached..

Any ideas how i can do this in c#

I really dont want to have to do a ping ip followed by an arp ip..

Thanks

Jonny
 
R

Ryan Rogers

Why do you want to write it in C#?

-R
jonny said:
hi all,

I would like to write a network discovery tool, that will go through a
given ip range and see what devices are connected to the network. I would
also liek to be able to get the MAC address' of the devices attached...
 
R

Ryan Rogers

Jonny,

Anything is possible with just have to have an approach
Do you know how to write it in anything else?? becasue your still going to
be using winsock or System.Net.Sockets so if you know how to use that your
set. Myself if I were to approach this I would maybe do something like the
following. For pinging.. send an ICMP Echo Request adn wait for the reply to
resolve the Hardware Address of an IP that you find alive. As Far as I
know System.Net.Sockets does not have an already configured header for ARP
packets so I would use the iphlpapi.dll library which exposes a SendArp call
whose only purpose is send an ARP request to obtain the physical address
that corresponds to the specified destination IP address. Hope this kind of
helps. So Yes it is possible to write it in C# how you go about doing that
is up to you.

--R
 
L

lancer

news:[email protected]...

I would like to write a network discovery tool, that will go through a
given ip range and see what devices are connected to the network. I
would also liek to be able to get the MAC address' of the devices attached...to do a ping ip followed by an arp ip...

The IP*Works! .Net Ping component
contains a GetMac function that will retrieve the MAC address of any given IP,
if it exists. You can use this to create a network discovery tool and retrieve
MAC addresses in one swoop. I've got a demo I'll be happy to send you if you
like.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-
 
R

Ryan Rogers

Jonny,
Ok The IP Helper API will allow you to do all you want... send ICMP and ARP
Packets which allow you to ping machines then resolve the mac address. Here
are the MSDN Links that can help you get started and below a small C#
Program that uses the SendARP Function to resolve the mac address of the
given IP.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/ip_helper_functions.asp
http://msdn.microsoft.com/library/d...ry/en-us/iphlp/iphlp/ip_helper_start_page.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/ip_helper_functions.asp

This is how you can use iphlpapi.dll to resolve a mac address

using System;
using System.Runtime.InteropServices;
using System.Net;
namespace MacResolver
{
class FindMac
{
[DllImport("iphlpapi.dll")]
public static extern int SendARP(int DestIP, int SrcIP,[Out]
byte[] pMacAddr, ref int PhyAddrLen);
[STAThread]
static void Main(string[] args)
{
IPAddress addr = IPAddress.Parse("172.26.36.38");
byte[] mac = new byte[6];
int len = mac.Length;
SendARP( (int)addr.Address,0,mac, ref len );
string macAddress = BitConverter.ToString(mac,0,len);
Console.WriteLine(macAddress);
Console.ReadLine();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top