For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > automatically open ports









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author automatically open ports
horizxon@gmail.com

2007-08-03, 10:01 pm

Im not sure where to post this as Im really looking for the
functionality not specifically that it have to be in the perl
language.

How would I make something that would automatically open the correct
ports for a certain machine without my having to be at the machine
goto 192.168.1.1 in a browser and open the ports manually? Can this be
done easily?

Thanks

Ken Foskey

2007-08-03, 10:01 pm

On Fri, 2007-08-03 at 15:49 -0700, horizxon@gmail.com wrote:
> Im not sure where to post this as Im really looking for the
> functionality not specifically that it have to be in the perl
> language.
>
> How would I make something that would automatically open the correct
> ports for a certain machine without my having to be at the machine
> goto 192.168.1.1 in a browser and open the ports manually? Can this be
> done easily?


I don't understand what you want.

a) Do you want a process to be brought up at boot or automatically when
the port is addressed

b) You would like a system that is somehow brought up and closed
automatically before and after use?

--
Ken Foskey
FOSS developer

Jeff Pang

2007-08-03, 10:01 pm



-----Original Message-----
>From: horizxon@gmail.com
>Sent: Aug 4, 2007 6:49 AM
>To: beginners@perl.org
>Subject: automatically open ports
>
>Im not sure where to post this as Im really looking for the
>functionality not specifically that it have to be in the perl
>language.
>
>How would I make something that would automatically open the correct
>ports for a certain machine without my having to be at the machine
>goto 192.168.1.1 in a browser and open the ports manually? Can this be
>done easily?
>


I don't know what's your intent for this.Do you mean when there's a connection to this host,it should open a port to accept the connection,at other time it shouldn't open that port?AFAIK,this is impossible.Though using some tools like PF port forwarding o
r LVS,you can't see the ports opened on a host but they are really on there,it's nothing you wanted here.
Instead you can always open a port on the host and accept the connection,but use firewall (like iptables) to filter the info you wanted and drop the info you unwanted.
Opening a port generally need to build a socket server.In perl it's easy to do,see 'perldoc IO::Socket' for the description.

--
Jeff Pang <pangj@earthlink.net>
http://home.arcor.de/jeffpang/
usenet@DavidFilmer.com

2007-08-04, 7:58 am

On Aug 3, 3:49 pm, horiz...@gmail.com wrote:
> How would I make something that would automatically open the correct
> ports


What do you mean by "open the ports?" Do you mean change your
firewall configuration so that traffic on particular port is allowed
to pass? (that's what most people would think of.) Or do you mean
start up an application that listens on a particular port?


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

horizxon@gmail.com

2007-08-04, 7:58 am

On Aug 3, 9:43 pm, pa...@earthlink.net (Jeff Pang) wrote:
> -----Original Message-----
>
>
>
> I don't know what's your intent for this.Do you mean when there's a connection to this host,it should open a port to accept the connection,at other time it shouldn't open that port?AFAIK,this is impossible.Though using some tools like PF port forwarding

or LVS,you can't see the ports opened on a host but they are really on there,it's nothing you wanted here.
> Instead you can always open a port on the host and accept the connection,but use firewall (like iptables) to filter the info you wanted and drop the info you unwanted.
> Opening a port generally need to build a socket server.In perl it's easy to do,see 'perldoc IO::Socket' for the description.
>
> --
> Jeff Pang <pa...@earthlink.net>http://home.arcor.de/jeffpang/


I'm sorry. I wasnt clear in my first post. A situation arises when my
router gets restarted, the internal ip addresses of the computers in
my home (192.168.1.100 and the like) are shifted around. Normally I
have the router forward some ports to one of my computers for a few
services that I like to have, like an ftp server.

What I want to do is create a perl script that runs in cron that will
make sure my router is forwarding the ports I want it to. But the
thing is, the only interface I know of for doing such things is the
web interface to my router. It needs the mouse to select checkboxes
and fill in textboxes. It would be great if I can script this action
to run on a regular basis especially since Im not always home when the
ips get switched around.

Thanks

Ken Foskey

2007-08-04, 7:01 pm

On Sat, 2007-08-04 at 02:47 +0000, horizxon@gmail.com wrote:
> I'm sorry. I wasnt clear in my first post. A situation arises when my
> router gets restarted, the internal ip addresses of the computers in
> my home (192.168.1.100 and the like) are shifted around. Normally I
> have the router forward some ports to one of my computers for a few
> services that I like to have, like an ftp server.


Sounds like dynamic IP addresses, DHCP.

Rather than solve the changing configuration, change the setup of your
machines. My home system has two static IP's allocated one my major
machine and one my son's so I can easily control it with filtering
rules.

DHCP can also map the mac address (physical number for the network card)
to a specific IP address. You might want to have a look at that.

In direct answer there is WWW:Mechanise that can connect to a web screen
and perform actions. IF you want to reconfigure a router then it is
possible that you would connect to the router webserver and reconfigure
it. I have to say I would not recommend this, you have lag between
reboot and rebuild for a start.

--
Ken Foskey
FOSS developer

Michael Scondo

2007-08-04, 7:01 pm

On Saturday 04 August 2007 04:47, horizxon@gmail.com wrote:
>
> I'm sorry. I wasnt clear in my first post. A situation arises when my
> router gets restarted, the internal ip addresses of the computers in
> my home (192.168.1.100 and the like) are shifted around. Normally I
> have the router forward some ports to one of my computers for a few
> services that I like to have, like an ftp server.
>
> What I want to do is create a perl script that runs in cron that will
> make sure my router is forwarding the ports I want it to. But the
> thing is, the only interface I know of for doing such things is the
> web interface to my router. It needs the mouse to select checkboxes
> and fill in textboxes. It would be great if I can script this action
> to run on a regular basis especially since Im not always home when the
> ips get switched around.
>
> Thanks




Hi,
this would be possible without too many trouble.

just get the html of your router's webinterface and grep the lines where you
can see if the settings are right.
If not, submit a cgi request to your router, where you set the correct
settings.

Perhaps you'd like to read something about cgi before.

However, I'd guess you could also assign a static IP to your pc.

Michael
horizxon@gmail.com

2007-08-05, 4:01 am

On Aug 4, 8:48 am, michael.sco...@arcor.de (Michael Scondo) wrote:
> On Saturday 04 August 2007 04:47, horiz...@gmail.com wrote:
>
>
>
>
>
>
>
>
> Hi,
> this would be possible without too many trouble.
>
> just get the html of your router's webinterface and grep the lines where you
> can see if the settings are right.
> If not, submit a cgi request to your router, where you set the correct
> settings.
>
> Perhaps you'd like to read something about cgi before.
>
> However, I'd guess you could also assign a static IP to your pc.
>
> Michael


I Like this method. I just have to figure out how to POST my data to
it correctly.

Thanks

Jeff Pang

2007-08-05, 4:01 am



-----Original Message-----
>From: Ken Foskey <foskey@optushome.com.au>
>In direct answer there is WWW:Mechanise that can connect to a web screen
>and perform actions. IF you want to reconfigure a router then it is
>possible that you would connect to the router webserver and reconfigure
>it. I have to say I would not recommend this, you have lag between
>reboot and rebuild for a start.
>


Also most routes have TELNET or SSH interface,you could use Net::Telnet or Net::SSH to execute the commands.

--
Jeff Pang <pangj@earthlink.net>
http://home.arcor.de/jeffpang/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com