How can I get the name and IP of all devices in my network or get the router IP that I am connected to?

♀尐吖头ヾ 提交于 2020-01-03 10:49:09

问题


Ok, so I am trying to write an application which works with a piece of hardware (a router). The first part of my application is to obviously detect if the device is on the network (either on the WAN side or the LAN side as the router can be accessed from both sides, whether you are connected to a down stream router or a directly to the router I am trying to access through the application) - I hope this is making sense.

The two options I have thought of to detect if the device is on the network are:

  1. Because I know the name of the device on the Network, could I get the application to compile a list of all the deices connected to the network and the check to see if the name of the device I am looking for is any of them?
  2. The second option would mean that the application could only connect automatically if the application was connected to the LAN side of the router, and therefore is not as favourable as the user would have to enter the IP of the router id they were trying to access from the WAN side. The way I would do it is simply get the default gateway of the router through the allocation somehow and then just send an API request to it and see if it replies (if it replies I can assume I have connected to the correct device).

So to sum up is that I either need a way to get the names + IPs of all the devices connected to the network I am on (that is the preferable solution) or a way to get the default gateway (router IP address).

I am very new to this, so please be over informative for me so that I understand. I would appreciate it if you could really explain how to implement this, maybe so that I can just have it print it out in the console - then I can implement it into my program and do what I need to do.


回答1:


Getting the router's IP is easy if you got IP from DHCP because your default router is the IP address of your router.

route print | find " 0.0.0.0"


来源:https://stackoverflow.com/questions/29331227/how-can-i-get-the-name-and-ip-of-all-devices-in-my-network-or-get-the-router-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!