wifi.ping()

Greetings!

Can someone help me to figure out how to get host names by IP numbers when I'm doing LAN scan?

Here is my code which is scanning my LAN

#include <ETH.h>
#include <WiFi.h>
#include "ping.h"

void setup()
{
  Serial.begin(9600);
  
  WiFi.begin("my-ssid","my-password");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.begin(115200);

}

bool pingtest (IPAddress ia) {
  IPAddress adr = IPAddress(ia[0], ia[1], ia[2], ia[3]);
  Serial.printf("Ping : %d.%d.%d.%d : ", ia[0], ia[1], ia[2], ia[3]);
  
  if (ping_start(adr, 1, 0, 0, 1)) {
    Serial.println("OK");
    return true;
  } else {
    Serial.println("Request time out");
    return false;
  }

}

void loop(){

  for(int i = 100; i <= 150; i++){
    pingtest( IPAddress(192,168,1,i));
  }

}

and this is my outputs

Ping : 192.168.1.100 : Request time out
Ping : 192.168.1.101 : Request time out
Ping : 192.168.1.102 : Request time out
Ping : 192.168.1.103 : Request time out
Ping : 192.168.1.104 : Request time out
Ping : 192.168.1.105 : Request time out
Ping : 192.168.1.106 : OK
Ping : 192.168.1.107 : Request time out
Ping : 192.168.1.108 : OK
Ping : 192.168.1.109 : OK
Ping : 192.168.1.110 : OK
Ping : 192.168.1.111 : OK
Ping : 192.168.1.112 : OK
Ping : 192.168.1.113 : OK
Ping : 192.168.1.114 : Request time out
Ping : 192.168.1.115 : Request time out
Ping : 192.168.1.116 : Request time out
Ping : 192.168.1.117 : Request time out
Ping : 192.168.1.118 : Request time out
Ping : 192.168.1.119 : Request time out
Ping : 192.168.1.120 : OK

So instead of "OK" I would to see machine name if possible.

Thank you

That is called reverse DNS lookup. In many cases you won't get the names you probably expect as the reverse lookups usually are technical names which have no relation to the service the host offers.

If it's your own network I doubt that the hosts have a reverse lookup at all.

Thank you for answer Pyon.

My question is how to get workstation host name if you know IP in Arduino.

Thanks.

My question is how to get workstation host name if you know IP in Arduino.

That's exactly what my answer tells you. It might be a problem that not all people have the same meaning of the term "host name". In the professional IT world it's the host's DNS name. But here in the forum I read several other definitions from DHCP identifier to mDNS service name. What is your understanding?

Yes, i think we talking about same thing, so if you can, please help me to get host name/machine name.
Thank you

You are going to have to setup a Domain Name Server on your network.

Yes, i think we talking about same thing, so if you can, please help me to get host name/machine name.

Do you have your own DNS server for your network? If the answer is no, you either have to set it up and configure it appropriately or forget to see host names instead of IP addresses because there is no way to get to the host names.
But I'm quite sure we're not talking about the same thing. So please make some examples of what kind of host names you'd expect to see in the output.