Forum > Networking and Web Programming

how to scan a network ?

(1/2) > >>

ProfHarry:
Hello,

I'm french so my english is not so good and my friend Deepl help me  ;-)

I have a set of ESP32 microcontrollers which are HTTP servers and DHCP clients on a wifi network.
The only user interface is the web page, so it is difficult for the user to know the IP addresses of the various microcontrollers. In general, the DHCP server and the list of leases are not accessible to users.

Each ESP32 responds to the URL http://IP/info.txt with a line containing, among other things, its IP address and hostname.

I therefore tried to develop a Lazarus application to scan the network and make this request to all the addresses.
But it's very, very slow... Because of the timeout for most addresses, it takes more than 10 minutes to scan an entire /24 network. I can't even imagine on a /16 network.

I use this code called in a loop on all IP addresses:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetInfos(IP : string) : string;Var  URL : String;  SL : TStringList;begin  URL := 'http://' + IP + '/infos.txt';  SL := TStringList.Create();   try    with TFPHttpClient.Create(Nil) do      try        AllowRedirect := True;        Get(URL,SL);        application.processmessages;      finally        Free;      end;    Result := SL[0];  finally    SL.Free;  end;end; 
Do you see a solution to speed up the scan and make it possible on a larger network?
Thanks for your help.

alpine:
Couldn't you just send an UDP broadcast packet with the server IP and then all nodes to reply with their info back?
This is pretty trivial, I've done it before but not in FPC ie. don't have a source to show it.

ProfHarry:
Yes, it's a great idea! Instead of searching for ESP32s from the lazarus program, I wait for the ESP32s to show up.

It's simpler in principle. All that's left is to implement it.

dsiders:

--- Quote from: ProfHarry on May 19, 2024, 11:46:38 pm ---Yes, it's a great idea! Instead of searching for ESP32s from the lazarus program, I wait for the ESP32s to show up.

It's simpler in principle. All that's left is to implement it.

--- End quote ---

Sounds like multicast DNS (mDNS) to me.

https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/protocols/mdns.html
https://lastminuteengineers.com/esp32-mdns-tutorial/

ProfHarry:

--- Quote from: dsiders on May 20, 2024, 12:13:10 am ---Sounds like multicast DNS (mDNS) to me.

--- End quote ---

I tried to use mDNS but :
- you need to know the name
- it doesn't work on all browsers/OS

Navigation

[0] Message Index

[#] Next page

Go to full version