OK, I'm trying to write a script to grab the MAC Address of a client using the clients IP. Here's the code that I got from developersdex.com written by Armoghan Asif:
CODE START
public string IP2Mac(string IP )
{
string result = "Not found";
try
{
ProcessStartInfo psi = new ProcessStartInfo("nbtstat", "-A "+ IP);
Process proc = new Process();
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow= true;
psi.UseShellExecute = false;
proc.StartInfo = psi;
proc.Start();
proc.WaitForExit();
StreamReader sr = proc.StandardOutput;
StreamReader err = proc.StandardError;
string str = "";
bool looking = true;
while (looking )
{
str = sr.ReadLine().Trim().ToLower ();
int i = str.IndexOf("mac address = ");
if(str == null )
looking = false;
if ( i != -1)
{
result = str.Substring (i + "mac address = ".Length );
looking = false;
}
}
}
catch (Exception err)
{
Console.Error.WriteLine(err.Message);
}
return result;
}
CODE END
I pass in the IP from a remote client. I'm coding with Visual Web Developer 2005 express edition. Using the web server with VWD 2005 EE, it works great. But using IIS 5.1, the MAC returns NOT FOUND. I placed Response.Write("Some text") before the while loop and after the while loops closing curly brace. I also added a counter variable that I print to the screen during the while loops execution. The Response.Write("Some text") that is placed before the while loop gets executed. None of the other ones do in IIS 5.1. So when running the code in IIS 5.1 (this is on Windows XP SP2), it goes into the function, starts the processes but totally skips the while loop and the Response.Write code after the closing curly brace of the while loop. Any ideas why this would happen?