简单网络扫描仪仅适用于无线但无线

时间:2014-03-15 02:48:06

标签: c# .net networking ip

我发现这个C#代码用于简单的IP网络扫描程序,它扫描网络中连接的主机并显示其物理地址和IP地址。它只能在通过WIFI与网络连接时运行良好。当通过网络通过网络连接时,它不起作用。

[DllImport("iphlpapi.dll", ExactSpelling = true)]

首先,iphlpapi.dll已导入。所以,你能解释一下吗?其余代码如下所示。

// Use Your work Group WinNT://&&&&(Work Group Name)
DirectoryEntry DomainEntry = new DirectoryEntry("WinNT://" + this.TxtWorkGroup.Text.Trim());
DomainEntry.Children.SchemaFilter.Add("computer");


// To Get all the System names And Display with the Ip Address
foreach (DirectoryEntry machine in DomainEntry.Children)
{
    string[] Ipaddr = new string[3];
    Ipaddr[0] = machine.Name;

    System.Net.IPHostEntry Tempaddr = null;

    try
    {
        Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(machine.Name);
    }
    catch (Exception)
    {
        MessageBox.Show("Unable to connect with the system :" + machine.Name);
        continue;
    }
IPAddress[] TempAd = Tempaddr.AddressList;
    foreach (IPAddress TempA in TempAd)
    {
        Ipaddr[1] = TempA.ToString();

        byte[] ab = new byte[6];
        int len = ab.Length;

        // This Function Used to Get The Physical Address
        int r = SendARP((int)TempA.Address, 0, ab, ref len);
        string mac = BitConverter.ToString(ab, 0, 6);

        Ipaddr[2] = mac;
    }

ListViewItem TempItem = new ListViewItem(Ipaddr);

    this.ListHostIP.Items.Add(TempItem);
}


}

1 个答案:

答案 0 :(得分:0)

关闭WIFI适配器并再试一次。