IPAddress[] ipadd;
string hostname = Dns.GetHostName();
ipadd=Dns.GetHostAddresses(hostname);
foreach (IPAddress ip in ipadd)
{
MessageBox.Show(hostname);
MessageBox.Show(ip.ToString());
}
string hostname = Dns.GetHostName();
ipadd=Dns.GetHostAddresses(hostname);
foreach (IPAddress ip in ipadd)
{
MessageBox.Show(hostname);
MessageBox.Show(ip.ToString());
}
p.StartInfo.FileName = "net";
p.StartInfo.Arguments = "view";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string s = p.StandardOutput.ReadLine();
if (s.StartsWith(@"\\"))
{
try
{
Console.WriteLine(Dns.GetHostByName(s.Substring(2, s.IndexOf(' ') - 1)).AddressList[0].ToString());
}
catch { }
}
}
http://www.microsoft.com/china/community/program/originalarticles/TechDoc/DirectoryEntry.mspx
效果如下图:
DirectoryEntries domains = root.Children;
domains.SchemaFilter.Add("domain");
foreach (DirectoryEntry domain in domains) {
IPHostEntry iphe = null;
try {
iphe = Dns.GetHostByName(computer.Name);
}
catch { }
}或
string strIPAddress="192.168.1.";
int nStrat = Int32.Parse("1");
int nEnd =Int32.Parse("255");
for(int i=nStrat;i<=nEnd;i++)
{
string strScanIPAdd = strIPAddress +i.ToString();
IPAddress myScanIP = IPAddress.Parse(strScanIPAdd);
try
{
IPHostEntry myScanHost = Dns.GetHostByAddress(myScanIP);
string strHostName =myScanHost.HostName.ToString();
this.listBox2.Items.Add(strScanIPAdd+"->"+strHostName+"\r");
}
catch
{
}
}
http://www.codeproject.com/KB/IP/Network_Computers.aspx