如何获取网络中所有设备的名称和IP或获取连接的路由器IP? [英] How can I get the name and IP of all devices in my network or get the router IP that I am connected to?

查看:382
本文介绍了如何获取网络中所有设备的名称和IP或获取连接的路由器IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我试图编写一个可以与硬件(路由器)配合使用的应用程序.我的应用程序的第一部分显然是要检测设备是否在网络上(在WAN端还是在LAN端,因为可以从两侧访问路由器,无论您是连接到下游路由器还是直接连接到下游路由器).我正在尝试通过应用程序访问的路由器)-我希望这是有道理的.

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. 因为我知道网络上设备的名称,我能否让该应用程序编译连接到网络的所有设备的列表,并检查我要查找的设备的名称是否为以下任何一种他们吗?
  2. 第二个选项意味着,仅当应用程序连接到路由器的LAN端时,该应用程序才能自动连接,因此不如用户必须输入他们尝试的路由器ID的IP那样有利.从WAN端访问.我要做的方法就是简单地以某种方式通过分配获得路由器的默认网关,然后向它发送一个API请求,看看它是否答复(如果答复,我可以假定我已连接到正确的设备). /li>
  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).

总而言之,我要么需要一种方法来获取连接到我所在网络的所有设备的名称+ IP(这是首选解决方案),要么需要一种方法来获取默认网关(路由器IP地址) ).

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.

推荐答案

如果从DHCP获得IP,则很容易获得路由器的IP,因为默认路由器是路由器的IP地址.

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"

这篇关于如何获取网络中所有设备的名称和IP或获取连接的路由器IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆