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
9 replies to this topic
#1
Posted 13 October 2011 - 11:47 PM
|
|
|
#2
Posted 14 October 2011 - 09:54 AM
It's certainly possible. You'll just have to write a program that emulates the calls that you normally make via your browser.
#3
Posted 14 October 2011 - 10:05 AM
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
Posted 14 October 2011 - 10:09 AM
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.
#5
Posted 14 October 2011 - 01:05 PM
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
How can i automatically communicate with the router?
I tried in Java too, using something like this:
but it tells me 401 unauthorized
what can 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
Posted 14 October 2011 - 01:19 PM
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
Posted 15 October 2011 - 12:49 AM
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:
<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?
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
Posted 18 October 2011 - 03:26 PM
What does your router page look like (screenshot) and what is its HTML source?
Latinamne loqueris?
#9
Posted 18 October 2011 - 11:28 PM
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
Posted 19 October 2011 - 01:51 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









