javawifirouter

How can I start/stop a Wireless Router through a Java Application?


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.


Solution

  • 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.