在不降低应用程序速度的情况下获取公共IP - VB.NET [英] Get public IP without slowing down the application - VB.NET

查看:58
本文介绍了在不降低应用程序速度的情况下获取公共IP - VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在不降低设备速度的情况下获取公共IP。如果不需要使用任何网站会更好,因为我认为这会减慢应用程序的速度,大约10秒钟。



我尝试过:



我使用了带有Downloadstring的Net.Webclient。但即使我得到IP结果,这也不是一个好选择。

解决方案

看起来你想要检测ISP分配给路由器的WAN IP地址(互联网服务提供商)。



您已尝试部分的常用方法是连接到返回所需信息的服务器。这可能是用于此类目的的特定服务,如 whatismyip.com 或返回此信息的协议。但是这些可能需要一些时间,暂时无法访问,甚至在使用位于本地网络之外的代理服务器时甚至是错误的。



因为WAN IP是不经常更改,您可以使用上述方法之一,并通过在后台线程中进行操作来避免阻止您的应用程序。



唯一可靠的方法需要您的应用程序可以访问路由器(例如,通过Telnet,SSH或Web界面,启用LAN访问,并且您的应用程序知道登录凭据),并且路由器提供查询此信息的选项(这取决于路由器型号)。 br />


大多数路由器也将此类信息写入日志文件。然后获取并解析该日志文件就足够了。


使用IPAddress类:



IPAddress Class(System.Net) [ ^ ]

I would like to know how to get the public IP without slowing down the device. It will be better if there is no need of using any websites as I think that slows down the application like around 10 seconds.

What I have tried:

I have used Net.Webclient with Downloadstring. But that is not a great option even though I get the IP result.

解决方案

It looks like you want to detect the WAN IP address assigned to the router by your ISP (Internet Service Provider).

The common method(s) you have already tried partially are connecting to a server that returns the required information. That may be either a specific service for such purposes like whatismyip.com or a protocol that returns this information. But these may require some time, be not accessible anymore / temporarily, and are even wrong when using a proxy server located outside your local net.

Because the WAN IP is not changing often, you can use one of the above methods and avoid blocking of your application by doing it in a background thread.

The only reliable method requires that your application has access to the router (e.g. via Telnet, SSH or web interface, access from LAN is enabled, and your application knows the login credentials) and that the router provides an option to query this information (which depends on the router model).

Most routers write such information also to a log file. It would be then suficient to get and parse that log file.


Use the IPAddress class:

IPAddress Class (System.Net)[^]


这篇关于在不降低应用程序速度的情况下获取公共IP - VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆