سؤال

I want to search the local network for special servers to communicate with. To achieve this I'm running a for-loop pinging all IP-Addresses in the range I give the function.

E.g. findServers("192.168.0.x", 101, 255) pings all addresses between 192.168.0.101 and 192.168.0.255 and, if they are reachable, tries to connect to a specific port to find out whether a server is running.

But I don't want to enter the range manually. Is there any way to get the IP-range in which the DHCP-server assigns addresses to the machines in the network?

هل كانت مفيدة؟

المحلول 2

You can look at the subnet for your machine and try to connect to the port in question. This saves you needing to know the specific address range the DHCP will give out.

You don't need to determine if the host is reachable because you would still have to attempt to connect to the port. If you connect to 255 addresses using a thread pool it will take a few seconds.

Instead of using TCP you could use UDP. UDP can send a broad cast to a whole subnet or multi-cast across networks with a single packet. This would allow you to send a request to any number of machines to find out if they have a service available.

نصائح أخرى

The only way to obtain this would be to ask the administrator of the DHCP server. One remote possibility is if the DHCP server exposed an SNMP server as well and that SNMP server provided the information. However, no sysadmin worth his/her salt would expose that information, so it's unlikely.

In short, the answer is about 99.9% likely to be "you can't".

There is no such protocol that propagates the available ip address range, provided by the DHCP server.

I know its old but maybe someone Google it. You can get it with PowerShell:

$dhcpserver = "10.17.5.1"
$ScopeList = Get-DhcpServerv4Scope -ComputerName $dhcpserver | Where-Object {$_.name -like "*toip*"}

ForEach($Scope in $ScopeList){

    $voip += Get-DhcpServerv4Lease -ComputerName $dhcpserver -ScopeId $Scope.ScopeId

}

This will only work if the scopes for Voips have a pattern like "toip".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top