David Connors wrote:
Ah right. So if you're after that then build on Les' suggestion.

1. Look at the local PC's IP configuration. Get the default gateway.
2. Issue and ARP request for the MAC address of that IP (fkd if I know how you do that in .NET). 3. Send that MAC to your web service.
If that MAC changes, then they have changed the router.

Step 1: Get the gateway address.

From: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/c4d1a32a-9bde-4178-bb97-acf7be038949

-------------------------------------

using System.Net.Networkinformation

PGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
foreach (NetworkInterface networkCard in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (GatewayIPAddressInformation gatewayAddr in networkCard.GetIPProperties().GatewayAddresses) {
       txt_gateip.Text = gatewayAddr.Address.ToString();
   }
}

-------------------------------------

Step 2: Send the machine a message so it's details are in your local arp table.

This will do: "ping IP.AD.DR.ESS -n 1"

Maybe something like this: (not tested)

|using (Process ping = new Process())
   {
       ProcessStartInfo startInfo = ping.StartInfo;
       startInfo.FileName = "ping.exe";
       startInfo.Arguments = "|IP.AD.DR.ESS -n 1|"; // www.example.com
       startInfo.UseShellExecute = false;
       startInfo.RedirectStandardOutput = true;
       ||ping||.Start();

       // here you could check your 'ping.StandardOutput' to see if the ping 
was successful, but who cares?
   }
|


Step 3: Check your ARP table.

This can be done by doing a "arp -a" in windows. Your output will be something like:

Interface: 10.0.2.15 --- 0x10003
 Internet Address      Physical Address      Type
10.0.2.2 00-12-DE-AD-BE-EF dynamic
So same deal as above, except run "arp.exe" with arguments "-a"

Then foreach line in the output, find the one that starts with your gateway IP address, and your MAC (Physical address) is right next to it. (split by blankspace/etc)

---------------------------------------

There are a few other ways you can do this with several dlls around, which avoids the 'hacky-type' process calls, but this should work, and ping.exe and arp.exe have been around and worked for a long time.

Good luck :)

--
Les Hughes
[email protected]

Reply via email to