Jump to content

Opening and close router ports via software

- - - - -

  • Please log in to reply
9 replies to this topic

#1
Nur Ab Sal

Nur Ab Sal

    Newbie

  • Members
  • PipPip
  • 12 posts
Hi all, I'm trying to write a C++ or java program that, for example using telnet, can open and close the router ports.
The router is a normal router Digicom Wavegate 108.
The pc is connected to the router via ethernet or via internet.

Do you think is this possible? Are there some universal telnet commands or i have to edit some files into the router?

Thank you all

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
It's certainly possible. You'll just have to write a program that emulates the calls that you normally make via your browser.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Nur Ab Sal

Nur Ab Sal

    Newbie

  • Members
  • PipPip
  • 12 posts
Yes you're right, but with telnet it would be a more elegant solution and it would work even when another (human) administrator is using the router

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You can only use whatever methods the router supports. If it supports a standard telnet connection, then fine. Telnetting to port 80 is the same as connecting to it the way a browser would.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Nur Ab Sal

Nur Ab Sal

    Newbie

  • Members
  • PipPip
  • 12 posts
ok i'm trying to get authenticated into my router. Manually i do:
telnet 192.168.0.1 80
enter
get / http/1.0
enter
Authentication: Basic username:passwdbase64
and i get as response:
HTTP/1.0 200 OK
Content-type etc

But if i try to write a c program using
system("telnet 192.168.0.1 80");
naturally it closes my program and it starts telnet waiting manual input.
How can i automatically communicate with the router?

I tried in Java too, using something like this:

        URL router= new URL("192.168.0.1");

        URLConnection yc = router.openConnection();

        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

        String inputLine;

        while ((inputLine = in.readLine()) != null) 

            System.out.println(inputLine);

        in.close();


but it tells me 401 unauthorized

what can i do?

#6
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
You can't use the system() command to do that in C, you need to either use Sockets (Winsock for windows) or use some kind of networking library.
Latinamne loqueris?

#7
Nur Ab Sal

Nur Ab Sal

    Newbie

  • Members
  • PipPip
  • 12 posts
Hi, thank you for the replies. Now I'm following WingedPanther advice. I wrote a simple Java method that emulates browser interactions.
I used Authenticator class to login and then I tried to add a rule with this code:

router = new URL("http://192.168.0.1/setup.cgi");

HttpURLConnection hConnection = (HttpURLConnection) router.openConnection();

hConnection.setFollowRedirects(true);

hConnection.setDoOutput(true);

hConnection.setRequestMethod("POST");

PrintStream ps = new PrintStream(hConnection.getOutputStream());

            ps.print("service_list=Any(ALL)&" +

                    "fwout_action=0&" +

                    "fwout_laniptype=singleip&" +

                    "lan_start_ip1=192&" +

                    "lan_start_ip2=168&" +

                    "lan_start_ip3=0&" +

                    "lan_start_ip4=99&" +

                    "lan_finish_ip1=192&" +

                    "lan_finish_ip2=168&" +

                    "lan_finish_ip3=0&" +

                    "lan_finish_ip4=99&" +

                    "fwout_waniptype=anyip&" +

                    "wan_start_ip1=192&" +

                    "wan_start_ip2=168&" +

                    "wan_start_ip3=0&" +

                    "wan_start_ip4=99&" +

                    "wan_finish_ip1=192&" +

                    "wan_finish_ip2=168&" +

                    "wan_finish_ip3=0&" +

                    "wan_finish_ip4=99&" +

                    "fwout_logging=1&" +

                    "todo=save&" +

                    "this_file=rule_out.htm&" +

                    "next_file=fw_rules.htm&" +

                    .........


i tried to define all the parameters that i found in the html code of the form. But when i send the request i get as response some html code with this at the
<script> alert("IP addres is not valid!"); </script><script> location.href="setup.cgi?next_file=rule_out.htm"; </script>

Now i don't know... is there any way to see if the HTTP request that i send is valid and the parameters well formatted?
or better.. is there any way to inspect the HTTP request that normally the browser sends to router when i submit the form?

#8
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
What does your router page look like (screenshot) and what is its HTML source?
Latinamne loqueris?

#9
Nur Ab Sal

Nur Ab Sal

    Newbie

  • Members
  • PipPip
  • 12 posts
sorry i forgot to reply saying that, thanks to chrome, i found the right parameters to send to the router and now works fine

#10
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Oh ok, cool :D
Latinamne loqueris?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users