Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
If MyIP.Contain("192.168") Then "This PC is behind a Router"
Posted
Updated 28-Oct-12 12:26pm
v2
Comments
Nelek 28-Oct-12 19:08pm    
If you are going to try it in that way, then you should ask for all private IPs: http://en.wikipedia.org/wiki/Private_network[^]

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.
 
Share this answer
 
Comments
[no name] 29-Oct-12 5:55am    
There must be a way to check if my PC is alone or behind a Router. I mean a Router must leave some footsteps which shows that it is present and if those infos lack then its not present.
Thanks
Dave Kreskowiak 29-Oct-12 7:58am    
THERE IS NO RELIABLE WAY TO DO THIS.

I already told you why.

What would you even do with this information anyway??
[no name] 29-Oct-12 12:09pm    
I want to Port-Forward a TCP Port for my app, using UPnP if theres a Router
Dave Kreskowiak 29-Oct-12 16:36pm    
OK, you're asking the same question as before. I didn't know you were the same person until now.

You DON'T look for a router.

You use the UPnP API's that you were provided before and the API handles searching for a UPnP compatible device for you.

I got this little sample to work very easily. Took about 5 minutes:
http://pietschsoft.com/post/2009/02/05/NET-Framework-Communicate-through-NAT-Router-via-UPnP.aspx
VB
' 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"


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'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900