0

我正在尝试打开端口,使用 UPNP 来执行此操作我正在使用 mono.nat

这是我的代码,它很简单,应该可以工作,但它会在每个代码上抛出“错误 402:无效的 NewPortMappingIndex”。“设备”的各种其他功能,如 GetExternalIP。

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AddHandler NatUtility.DeviceFound, AddressOf DeviceFound
    NatUtility.StartDiscovery()
End Sub

Private Sub DeviceFound(ByVal sender As Object, ByVal e As Mono.Nat.DeviceEventArgs)
    Debug.WriteLine("Found")
    Dim device As INatDevice = e.Device
    Debug.WriteLine(device.GetHashCode)
    For i = 0 To device.GetAllMappings.Length - 1
        Dim _PortMap As Mono.Nat.Mapping = device.GetAllMappings(i)
        ListBox1.Items.Add(_PortMap.Description & " | " & _PortMap.PrivatePort & " | " & _PortMap.Protocol & " | " & _PortMap.PublicPort)
    Next

End Sub

我也试过关闭我的防火墙和任何其他可能干扰的东西。我也知道我的路由器启用了 UPNP。

4

1 回答 1

0

这似乎循环了太多次:

对于 i = 0 到 device.GetAllMappings.Length

于 2013-09-26T07:02:19.317 回答