VB.NET-以编程方式检查我的PC是否在路由器后面 [英] VB.NET - Check if my PC is behind a router programmatically

查看:60
本文介绍了VB.NET-以编程方式检查我的PC是否在路由器后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我可以使用哪些方法检查我的PC是否在路由器后面.我用谷歌搜索,发现不合适的答案.
当我检查内部IP时是否已足够完成,因为我认为直接连线而不位于路由器后面的PC不会具有诸如内部IP之类的东西.我说的对吗?
这样的简单声明在我的问题上是否可靠:

I want to know with which methods i would be able to check if my PC is behind a Router. I googled and found not the appropriate answer.
Is it enough done when i check for Internal IP, since i believe that PCs directly wired without being behind a Router dont have such like Internal IPs. Am i right?
Would a simple Statement like this be reliable on my question:

If MyIP.Contain("192.168") Then "This PC is behind a Router"

推荐答案

您没有找到答案,因为没有可靠的答案. 在路由器后面"相对于网络上的目的地.对于任何给定的目标地址,您的机器与该目标之间可能没有路由器.

没有可靠的方法来检查您所获得的IP地址可能是也可能不是私有地址之一,无论哪种情况,您可能会或可能不在到达目的地的路由器内部.

网关地址不能保证路由器位于目标地址的路径上.

侦听各种路由器流量并不可靠,因为它可能会被过滤掉,因此您的机器听不到.
You haven''t found an answer because there isn''t a reliable one. "Behind a router" is relative to a destination on a network. For any given destination address, there may or may not be router between your machine and that destination.

There isn''t a reliable way to check as the IP address you''re given may or may not not be one of the private ones and, in either case, you may or may not be on the inside of a router to your destination.

The gateway address is not a guarantee of a router that''s on the path to a destination address.

Listening for various kinds of router traffic isn''t reliable as that may be filtered out so your machine can''t hear it.


' This is VBScripting
Set theNatter = CreateObject( "HNetCfg.NATUPnP")
Dim mappingPorts
Set mappingPorts = theNatter.StaticPortMappingCollection
mappingPorts.Add 1024, "TCP", 1024, "192.168.1.170", TRUE, "App"



这是VBScripting,如果您的路由器具有UPnP之类的选项(大多数都有),则将端口转发到UPnP表.
您应该记住的一件事是,UPnP选项不是那么可靠.至少即使启用了它并且信息存储在我的路由器上,它也无法在我的PC上运行,但是是的,某些东西阻止了UPnP,并确保它不是默认的Windows防火墙,因为我已经完全访问了我的TCP App,所以依靠它,但是您可以尝试.

为什么使用VBScript而不是VB.NET,答案是,在我满怀希望创建更高级的UPnP函数的那一点上,失败的VStudio 2010失败了.
NET Framework 2、3、3.5具有一些缺陷,无法从com库"UPnPLib"中检测"UPnPNatClass",或者直接引用"system32"下的"hnetcfg.dll",这是不一样的.在目标NET 4上构建它的案例.
我的目标目前是NET 2,这就是为什么我放弃并使用经典的"VBScript"来实现的原因.



This is VBScripting and forwards a port to the UPnP Table, if your Router has such an Option like UPnP (most do have).
One thing you should memorize, the UPnP option is not that reliable. At least it doesnt work on my PC even it is enabled and the infos are stored on my Router, but yeah something is blocking the UPnP and im sure its not the default Windows Firewall, because i gave full access to my TCP App, so not rely on this but you can try it.

Why VBScript and not VB.NET, the answer is that the f***ing VStudio 2010 failed on the point where i had all my hopes to create a more advanced UPnP Function.
NET Framework 2, 3 , 3.5 has some flaws to detect the ''UPnPNatClass'' from the com library ''UPnPLib'' or by referencing directly to ''hnetcfg.dll'' under ''system32'' which is not the same case building it on Target NET 4.
My Target is currently NET 2 and thats why i gave up and do it with the classic one ''VBScript''.


这篇关于VB.NET-以编程方式检查我的PC是否在路由器后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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