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