-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|679|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Internet


 
HoboBen
Created : 12 October 2008
Edited : 12 October 2008
Language : QBasic

Get Router Port Range Forwarding Rules

For a Linksys WRT54GS router

For Linux/Windows with Python (I suppose any system that can run python would work, but I can't give instructions)

The LAN IP address my computers are assigned by my router change every now and then, so for proper port-forwarding I have to check my IP address with the ifconfig command in the terminal (this would be ipconfig on windows.)

Then I have to open up firefox if it isn't already and click the bookmark for my router port forwarding page, and scan it for the IP address to see if it is set correctly, otherwise all my port forwarding rules will point to the wrong computers. (i.e. slow torrents, if I had a public-facing webserver, it wouldn't work, etc)

More often than not, it's set correctly and no further action is needed. So I decided to write a script that would just quickly pull the relevant data and display it in the terminal.

Works on my Wireless-G Broadband Router with SpeedBooster WRT54GS (My router is dead old though, so your milage may vary) Firmware Version: v1.50.5

You'll need Python installed and Beautiful Soup (download python script) in the same directory (or an includes directory?)

Disclaimer: Horrible code! My first time doing anything serious with python and I must say I hate it. Python as a shell isn't bad but as a scripting language it is IMO disgusting. Still, this awful code gets the job done, and that's all that mattered! Edit: I don't mean to come across as blaming python for my horrible code though - that's my fault!


|edit| Whoops - left my router password in. |edit|

Set password (line 6) to the password required for your router. If needed, change the router IP address (line 8)

On linux, the first time use chmod +x to enable permissions and use ./RouterForward.py to run. Windows... at a guess, python ./RouterForward.py

My results:


I've now aliased the commands to checkip. In your ~/.bashrc:



Here's what I would see in a browser:



I regret not doing it in PHP because I would have made a neater job of it (python might well have an explode command somewhere, but I was getting fed up ) but less people tend to have a usable PHP cli installed.

 

Comments


Sunday, 12 October 2008, 19:36
Orion Pax
Looks great ben. And I know what your talking about. But there is an easier work around. You can manually set your lan IP address! At least you can in windows. That is what I do so my port forwarding always works. I know how to go about doing it but not sure about the steps.
www.google.com/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&hl=en&q=how+to+manually+set+your+lan+ip+address&btnG=Google+Search

There's a lot of good topics there.

Its great that you went through all that just to make it easier. But this is a better long term solution. I might have to look at that later when I have time and check it out tho since you took the time to make it.
Sunday, 12 October 2008, 21:04
HoboBen
Thanks - I didn't think to do that. Now that I think of it there's a simple file in my Arch linux install at /etc/rc.conf where it's got the lines



So it looks like it will be easy to do, just uncomment the first line and get the right mask and broadcast IP addresses and comment out eht0="dhcp"

It's a bit too late to make the changes today, but I'll try it out tomorow. Thanks Orion! I had just assumed it was one of those quirks you had to live with.
Monday, 13 October 2008, 13:02
Orion Pax
No problem. My dad was the one that told me about that. Because of the same reason. Got tired of having to adjust my port forwarding settings every time my pc got a new lan IP address.
Wednesday, 15 October 2008, 16:57
mike_g
I regret not doing it in PHP because I would have made a neater job of it (python might well have an explode command somewhere, but I was getting fed up )

split() in python is pretty much the same as explode in php.

I'd recommend sticking with Python a bit longer, or at least I like it anyway, it just takes a while to get used comming from C-like languages.