0

所以......我想在vb.net中获得外部IP ......(不是内部192.168.0.100)而不使用像http://www.whatismyip.com这样的任何链接......所以我做了很多搜索谷歌,我得到了一个代码:

Public Function IpAddress()
    Dim strIpAddress As String
    strIpAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If strIpAddress = "" Then
        strIpAddress = Request.ServerVariables("REMOTE_ADDR")
    End If
    IpAddress = strIpAddress
End Function

或者

dim blabla as string = Request.ServerVariables("REMOTE_ADDR")

我导入了 sistem.web 和 sistem.net 我也安装了 web 开发工具包和 asp.net *但什么都没有... * 请求未声明

然后我把请求放在前面HttpContext.Current ... HttpContext.Current.request ....

我得到了这个错误: 对象引用未设置为对象的实例

4

3 回答 3

0

正如@Constantin Berhard 所说,你应该在外面问。

例如,您可以使用 Web 服务。您可以开发它或只使用您已知的 whttismyip。

在这里,您可以获得有关您可以使用的 API 的所有信息。

http://www.whatismyip.com/api-documentation/

于 2013-09-12T14:06:59.903 回答
0

如果服务器有一个外部域名,您可以对该域名进行 DNS 查找。您将依赖外部服务,而不是特定服务。

dim host as IPHostEntry = GetHostEntry("example.com")
于 2013-11-20T18:16:42.173 回答
0

您的计算机甚至不知道其外部 IP 地址。您必须询问外部计算机,因为您无法从内部看到外部 IP。

于 2013-09-12T13:55:17.503 回答