public override IList GetAddresses() {
ProcessStartInfo cmd = new ProcessStartInfo("/sbin/ifconfig");
cmd.RedirectStandardOutput = true;
cmd.UseShellExecute = false;
Process p = Process.Start(cmd);
string line = p.StandardOutput.ReadLine();
//string this_if = null;
Regex if_line = new Regex(@"^(\S+)\s+Link encap:");
Hashtable keys = new Hashtable();
keys["inet addr"] = new Regex(@"inet addr:([0-9\.]+)");
keys["Bcast"] = new Regex(@"Bcast:([0-9\.]+)");
keys["Mask"] = new Regex(@"Mask:([0-9\.]+)");
keys["HWaddr"] = new Regex(@"HWaddr ([0-9A-Fa-f:]+)");
keys["MTU"] = new Regex(@"MTU:([0-9]+)");
ArrayList result = new ArrayList();
Hashtable entry = null;
while( line != null ) {
//Get the interface:
Match m = if_line.Match(line);
if( m.Success ) {
/*
* This is a new Interface, add the old one to the list:
*/
if( entry != null ) {
result.Add(entry);
}
entry = new Hashtable();
//System.Console.Error.WriteLine(line);
Group g = m.Groups[1];
CaptureCollection cc = g.Captures;
//System.Console.Error.WriteLine(cc[0]);
entry["interface"] = cc[0].ToString();
}
IDictionaryEnumerator key_en = keys.GetEnumerator();
while(key_en.MoveNext() ) {
AddIfMatch((Regex)key_en.Value, line, entry, (string)key_en.Key);
}
line = p.StandardOutput.ReadLine();
}
if( entry != null ) {
result.Add(entry);
}
p.Close();
return result;
}
}