Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单的网络扫描仪只能无线工作,不能有线工作_C#_.net_Networking_Ip - Fatal编程技术网

C# 简单的网络扫描仪只能无线工作,不能有线工作

C# 简单的网络扫描仪只能无线工作,不能有线工作,c#,.net,networking,ip,C#,.net,Networking,Ip,我发现这个C#代码用于简单的IP网络扫描仪,它扫描网络中连接的主机,并显示其物理地址和IP地址。它工作正常,但只有通过WIFI连接到网络时才能工作。当通过网络通过电线连接时,它不工作 [DllImport("iphlpapi.dll", ExactSpelling = true)] 首先,iphlapi.dll已导入。那么,你能解释一下吗?下面给出了代码的其余部分 // Use Your work Group WinNT://&&&&(Work Group Na

我发现这个C#代码用于简单的IP网络扫描仪,它扫描网络中连接的主机,并显示其物理地址和IP地址。它工作正常,但只有通过WIFI连接到网络时才能工作。当通过网络通过电线连接时,它不工作

[DllImport("iphlpapi.dll", ExactSpelling = true)]
首先,
iphlapi.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);
}


}

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

在我看来,仅仅是连接方法不太可能是原因所在-我会关注这是否真的是真的。看看IPHLAPI的全部内容:oyu是否对上述代码有异常?我只是想知道是否有可能对此代码进行更改因此,它可以在通过导线连接时显示结果。如果是,我怎么做?请建议。