简体   繁体   English

如何通过Java应用程序启动/停止无线路由器?

[英]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. 我想编写一个小型应用程序,以确保如果最近30分钟内没有数据包传输,路由器将停止/关闭。 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. 确切地说,我想关闭路由器/通过Java程序重新启动路由器,不顾一切地从一些经验丰富的编码人员那里寻求建议。

Any help would be welcome. 任何帮助都将受到欢迎。

Thanks 谢谢

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). 我自己的路由器没有我知道的API,该API可以通过Java程序直接访问它(尽管您可能有所不同)。

My router does have a web interface and can be accessed over HTTP. 我的路由器确实具有Web界面,可以通过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 . 要使用Web界面,您需要首先找到Web服务器的IP-可能是192.168.1.1或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. 在开发人员工具中打开网络标签的情况下按此按钮(如果您不确定这意味着使用google),并捕获其使用的网址。

Now you have the IP and the request you can mimic this and send the same request directly using your Java code. 现在您有了IP和请求,您可以模仿它并使用Java代码直接发送相同的请求。 Again to find out how look online. 再次查找在线外观。 For example Sending HTTP POST Request In Java 例如, 以Java发送HTTP POST请求

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. 我建议不要使用原始套接字监听所有流量,并监视运行Java程序的设备的Web界面上的所有内容。 Alternatively you can use an existing solution like TCPDump which will do the same. 或者,您可以使用现有的解决方案,例如TCPDump ,该方法将执行相同的操作。

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM