0

I'm facing a problem nowadays with my home router. I want to write a small application that will ensure the router will stop/switch off if no packets transmitted in last 30 minutes. Is there a way to do?

Precisely, I want to switch off my router/start it back through a Java program, desperately looking for some suggestion from some experienced coder.

Any help would be welcome.

Thanks

1 Answers1

1

I guess the answer is that it depends on which router you have and what kind of interface it provides for controlling it.

My own router has no API that I know of which allows it to be directly accessed via a Java program (although yours might be different).

My router does have a web interface and can be accessed over HTTP. Conceivably by making the right post request I would be able to power off my router. I imagine you might find that yours is similar.

EDIT (added text)

To use the web interface you need to first find the IP of the webserver - probably 192.168.1.1 or 192.168.1.254 . Type this into your browser to get the control panel and find the button that turns off the router. Press this button with the network tab open in the developer tools (if you're not sure what this means use google) and capture the url it uses.

Now you have the IP and the request you can mimic this and send the same request directly using your Java code. Again to find out how look online. For example Sending HTTP POST Request In Java

END EDIT

The other problem you have is monitoring traffic to and from your router. You can do this a number of ways. Off the top of my head I would suggest using a raw socket to listen for all traffic and monitor everything that goes across the web interface of the device running your Java program. Alternatively you can use an existing solution like TCPDump which will do the same.

The question you have asked is very broad with a number of reasonable answers - it is also a kind of big question - so I have tried to provide some reasonable thoughts to get you started rather than actually write the code for you.

Hope this helps.

Community
  • 1
  • 1
Sam Redway
  • 6,145
  • 2
  • 22
  • 35
  • Thank you Sam. I can understand there may not be many API's for this. It's kind of thought that came in my mind yesterday when I was about to leave the home while keeping the router "on". If I can have some software to switch it off automatically, I can reduce the chance to "unwanted access/hacking" for my device. – Jayanta Mandal Sep 19 '16 at 05:14
  • I have a DSL 600 router at home, one I/P and 3 O/P box. – Jayanta Mandal Sep 19 '16 at 05:15
  • I suggest you look at the documentation for your router and check online to see if there is an API through which you can access it. If not you will most likely have a web interface anyway - as I say. I have edited my answer to give a little more detail on how to do this - but for more specifics you will need to look online. If my answer is helpful then please accept it as the answer. – Sam Redway Sep 19 '16 at 19:18