Hello,
I've designed and programmed a board to communicate with other devices with Ethernet. Everything works fine and in this step I need to create an IP scanner to scan an IP range (for example 192.168.1.100 to 192.168.1.254) but it takes more than one hour to scan this range of IP( 155 IPs) and connect to one device which is located at 192.168.1.150 . Here is my IP scanner code:
int ScanTheNetwork(void) { int i; NET_ADDR4 addr = { NET_ADDR_IP4, 5000, 192, 168, 1, 0 }; netInitialize (); netDHCP_Disable (0); socket1[0].SCK = netTCP_GetSocket (tcp_cb_func); for(i=100;i<255;i++) { addr.addr[3]=i; if (socket1[0].SCK >= 0) { netTCP_SetOption (socket1[0].SCK , netTCP_OptionTimeout, 1); netTCP_Connect (socket1[0].SCK, (NET_ADDR *)&addr, 0); netTCP_SetOption (socket1[0].SCK , netTCP_OptionTimeout, 1); while(1) { IWDG_ReloadCounter(); if(netTCP_GetState (socket1[0].SCK)==netTCP_StateUNUSED || netTCP_GetState (socket1[0].SCK)==netTCP_StateUNUSED) { netTCP_Close(socket1[0].SCK); }else if(netTCP_GetState (socket1[0].SCK)==netTCP_StateESTABLISHED) { return i; } } } } }
In the above code I need to find a device ( I didn't put many devices) which is alive and its open port is 5000. I changed the IP range from (148 to 152 ) which the alive one is located at 150 but it takes more than 5minutes to connect to my devices.
I need to know what is best way to find my alive device and connect to it as soon as possible in the an IP range.