Page 1 of 1

OT: Algorithm for port open test

Posted: Thu May 10, 2012 7:10 am
by josephj
Over the years, I've had a lot of problems with closed ports. I've gotten pretty good at fixing these (with help from this forum) once I figure out/notice that the port's closed. To that end, I want to write a piece of code (preferably in bash) that will test a port for open/closed. I'll use it to put something on my desktop or notifier to alert me to the problem.

Since Transmission already has code like that (Preferences-> Network->Test Port), I was hoping someone could tell me how it works. I probably don't know the language Transmission is written in, but I do know enough programming languages to mudde through foreign code and get a fair idea of what it's doing if I have to.

I have a notebook (kubunbtu oneiric (11.10) Linux x86) that uses dhcp, so I don't have a static IP and the IP varies depending on where the notebook is anyway.

So far, the hard part is getting my external dynamic IP address. Once I have that, testing the port is no problem.

I'd really like to do this without parsing some HTML page returned by a website or router. That' s a can of worms.

Since I'm testing a port on my own system, it shouldn't get anyone upset like port scanning does.

TIA

Joe

Re: OT: Algorithm for port open test

Posted: Thu May 10, 2012 8:08 pm
by rb07
josephj wrote:the hard part is getting my external dynamic IP address
Hard? Why don't you just read it from your router.
josephj wrote:I'd really like to do this without parsing some HTML page returned by a website or router
That's the easy way.

The alternative depends on your router, if it is running Linux (like many routers do), then you can by-pass the html and read a text file, or the output of the network configuration and pick out the WAN address.

As for testing the port... again the easiest way is using a Web page, but not always reliable (see Ticket #4702).

Or if you have access to an external system (for instance, you want to test your home setting, and have access to a remote computer, maybe at work) then you can set up a client-server testing scheme. But that is not simple, the server used currently is probably simulating a tracker or peer interaction to see if your client responds, this simulation can be done with curl as long as you know what to send (the protocol).

Re: OT: Algorithm for port open test

Posted: Sat May 12, 2012 2:02 am
by josephj
Thanks. I was hoping for something more reliable, but apparently I have to build my own server for that.
The problems with using a router is that this is a notebook and the router it sees will change with its physical location. Also, my code would probably break every time the router firmware gets upgraded. in the mean time, I'll use a public web service and try not to poll it too often.