如何检测LAN上的主机?

时间:2020-11-28 07:17:34

To help users, I would like my code to discover Oracle databases on the LAN. I thought to do this by first detecting all hosts, then checking each host to see if it is listening on Oracle's default port.

为了帮助用户,我希望我的代码能够在局域网上发现Oracle数据库。我想通过首先检测所有主机,然后检查每个主机以查看它是否正在监听Oracle的默认端口来实现此目的。

Any ideas how to go about this? Preferably in Java, but any language or algorithm would do.

任何想法如何去做?最好是Java,但任何语言或算法都可以。

6 个解决方案

#1


Are you using DHCP? If so, your DHCP server has a list of the leases it has passed out. That should do you for a list of hosts on the LAN. Then try opening a connection to the Oracle port on each of those hosts and see if it accepts the connection.

你在使用DHCP吗?如果是这样,您的DHCP服务器就有一个已经传递的租约列表。这应该是你在LAN上的主机列表。然后尝试打开与每个主机上的Oracle端口的连接,并查看它是否接受连接。

It should be pretty simple to implement as a shell script with half a dozen lines or so. Java seems like overkill for something like this. Loop through the leases file, grab the IP from each lease, and telnet to the Oracle port; if it connects, disconnect and print the IP to standard out.

将它作为一个包含六行左右的shell脚本实现起来应该非常简单。对于像这样的东西,Java似乎有些过分。循环访问租约文件,从每个租约中获取IP,然后telnet到Oracle端口;如果它连接,断开连接并将IP打印到标准输出。

#2


If you want to stay platform-independant, and unless you have access to some kind of database that lists the hosts, the only way to get a list is to try each IP address in the local network - might as well try to connect to the Oracle port on each of them.

如果你想保持平*立,除非你有权访问列出主机的某种数据库,获取列表的唯一方法是尝试本地网络中的每个IP地址 - 不妨尝试连接到每个都有Oracle端口。

There are lots of problems with this approach:

这种方法存在很多问题:

  • Will only search through the local network, which may only be a small part of the LAN (in case of large companies with lots of subnets)
  • 只搜索本地网络,这可能只是局域网的一小部分(如果大公司有很多子网)

  • Can take a long time (you definitely want to reduce the timeout for the connection attempts, but if someone has configured his LAN as a class A network, it will still take forever)
  • 可能需要很长时间(您肯定希望减少连接尝试的超时,但如果有人将其LAN配置为A类网络,它仍将需要永久)

  • Can trigger all kinds of alerts, such as desktop users' personal firewalls, and intrusion detection systems - because you're doing exactly the same thing someone trying to exploit a security hole in Oracle servers would do
  • 可以触发各种警报,例如桌面用户的个人防火墙和入侵检测系统 - 因为你正在尝试利用Oracle服务器中的安全漏洞做同样的事情

#3


As brazzy points out, scanning for hosts is likely to cause problems, especially if there is a bug in your scanner.

正如brazzy指出的那样,扫描主机可能会导致问题,特别是如果扫描仪中存在错误。

A better approach may be to get the owners of the databases to register them somewhere, for example in a local DNS service (or does Oracle have zeroconf support?), or simply on some intranet webpage or wiki.

更好的方法可能是让数据库的所有者在某个地方注册它们,例如在本地DNS服务中(或Oracle是否支持zeroconf?),或者只是在某个Intranet网页或wiki上。

#4


You better register the SID names/addresses to some server with a fixed address(maybe with a simple web service), and then query the list from there. Another approach is the bruteforce one (explained by @brazzy) by scanning one or more subnets, but this isn't really a good thing to do.

您最好将SID名称/地址注册到具有固定地址的某个服务器(可能使用简单的Web服务),然后从那里查询列表。另一种方法是通过扫描一个或多个子网来实现强力扫描(由@brazzy解释),但这并不是一件好事。

#5


In case you are looking for a tool Loo@Lan can do this for you. Unfortunately there's no source available...

如果你正在寻找一个工具Loo @ Lan可以为你做这个。不幸的是没有可用的来源......

#6


All of these smart answers are the reasons why many companies do not use the default port. Using a different port for each database is entirely possible, you know.

所有这些聪明的答案都是许多公司不使用默认端口的原因。你知道,完全可以为每个数据库使用不同的端口。

#1


Are you using DHCP? If so, your DHCP server has a list of the leases it has passed out. That should do you for a list of hosts on the LAN. Then try opening a connection to the Oracle port on each of those hosts and see if it accepts the connection.

你在使用DHCP吗?如果是这样,您的DHCP服务器就有一个已经传递的租约列表。这应该是你在LAN上的主机列表。然后尝试打开与每个主机上的Oracle端口的连接,并查看它是否接受连接。

It should be pretty simple to implement as a shell script with half a dozen lines or so. Java seems like overkill for something like this. Loop through the leases file, grab the IP from each lease, and telnet to the Oracle port; if it connects, disconnect and print the IP to standard out.

将它作为一个包含六行左右的shell脚本实现起来应该非常简单。对于像这样的东西,Java似乎有些过分。循环访问租约文件,从每个租约中获取IP,然后telnet到Oracle端口;如果它连接,断开连接并将IP打印到标准输出。

#2


If you want to stay platform-independant, and unless you have access to some kind of database that lists the hosts, the only way to get a list is to try each IP address in the local network - might as well try to connect to the Oracle port on each of them.

如果你想保持平*立,除非你有权访问列出主机的某种数据库,获取列表的唯一方法是尝试本地网络中的每个IP地址 - 不妨尝试连接到每个都有Oracle端口。

There are lots of problems with this approach:

这种方法存在很多问题:

  • Will only search through the local network, which may only be a small part of the LAN (in case of large companies with lots of subnets)
  • 只搜索本地网络,这可能只是局域网的一小部分(如果大公司有很多子网)

  • Can take a long time (you definitely want to reduce the timeout for the connection attempts, but if someone has configured his LAN as a class A network, it will still take forever)
  • 可能需要很长时间(您肯定希望减少连接尝试的超时,但如果有人将其LAN配置为A类网络,它仍将需要永久)

  • Can trigger all kinds of alerts, such as desktop users' personal firewalls, and intrusion detection systems - because you're doing exactly the same thing someone trying to exploit a security hole in Oracle servers would do
  • 可以触发各种警报,例如桌面用户的个人防火墙和入侵检测系统 - 因为你正在尝试利用Oracle服务器中的安全漏洞做同样的事情

#3


As brazzy points out, scanning for hosts is likely to cause problems, especially if there is a bug in your scanner.

正如brazzy指出的那样,扫描主机可能会导致问题,特别是如果扫描仪中存在错误。

A better approach may be to get the owners of the databases to register them somewhere, for example in a local DNS service (or does Oracle have zeroconf support?), or simply on some intranet webpage or wiki.

更好的方法可能是让数据库的所有者在某个地方注册它们,例如在本地DNS服务中(或Oracle是否支持zeroconf?),或者只是在某个Intranet网页或wiki上。

#4


You better register the SID names/addresses to some server with a fixed address(maybe with a simple web service), and then query the list from there. Another approach is the bruteforce one (explained by @brazzy) by scanning one or more subnets, but this isn't really a good thing to do.

您最好将SID名称/地址注册到具有固定地址的某个服务器(可能使用简单的Web服务),然后从那里查询列表。另一种方法是通过扫描一个或多个子网来实现强力扫描(由@brazzy解释),但这并不是一件好事。

#5


In case you are looking for a tool Loo@Lan can do this for you. Unfortunately there's no source available...

如果你正在寻找一个工具Loo @ Lan可以为你做这个。不幸的是没有可用的来源......

#6


All of these smart answers are the reasons why many companies do not use the default port. Using a different port for each database is entirely possible, you know.

所有这些聪明的答案都是许多公司不使用默认端口的原因。你知道,完全可以为每个数据库使用不同的端口。