|
-
May 6th, 2008, 08:25 AM
#1
Thread Starter
Member
programtically determine port routed
I have a client server application working but I need to know how to verify a port is open and routed to the client machine.
Basically a small network diagnostic to make sure a port is routed correctly if a router is used in a network.
edit for clarity - I am using a TCP sockets server / client and writing in VB 2005
I want to be able to verify a network connection on a specific port is available before streaming a file to them, but I want this to be a user defined port. so user enters port 2500 as the port to use and the client would ask the server to verify the port is open and can receive data on that port even if inside a network.
Last edited by gomer; May 6th, 2008 at 03:07 PM.
-
May 6th, 2008, 12:57 PM
#2
Junior Member
Re: programtically determine port routed
Private Sub cmdConnect_Click()
Winsock1.RemoteHost = "" 'Change this to your host ip
Winsock1.RemotePort = 80
Winsock1.Connect
End Sub
Use the winsock control, and the command button. I'm not sure how to check to see if there is a router, but this should do the trick.
-
May 7th, 2008, 12:33 AM
#3
Re: programtically determine port routed
There are a few things to consider. In order for the Cilent to 'ask' the Server if a particular Port is available it must already be connected to the Server on a 'known' Port. Once the question has been asked, the server will have to interrogate the Router in order to ascertain if Port Forwarding has been enabled for that Port. Also, any Firewall in use will have to be interrogated, by the Server, to ensure that it is not blocked.
How you perform all those checks will depend entirely on the Router and Firewall employed in the configuration in question. I don't hink that there is a generic solution.
-
May 7th, 2008, 03:11 AM
#4
Re: programtically determine port routed
I used to think to see if a port is "accessible" on a computer you would need to have another (outside) machine try to connect on that port, and if connection is successful then the port is open.
But after wasting a lot of my time doing that, I realized if the user attempts to connect to themself ("external"/internet IP) on that port, and it is not open, the connection will fail.
So really, you just need to get your external IP and attempt to connect to it from the same program.
http://www.vbforums.com/showthread.php?t=469768
Then you can use John_420's code on that IP/port.
If connection fails, there is a router or firewall in the way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|