Clément 148 Posted December 21, 2023 Hi.... I using ICS9.x with D12. My application (dhsPinger) have to ping several devices on a LAN. Today I using a thread pool to ping, works nicely. I would like to implement TCP ping using ICS and I was wondering if it's possible. All I need is to know if there's a device on the other side. A device can be any device that can be attached to a LAN. Would if be possible to discover any device via TCP ping or some devices would be undectected? Would there be any cons ? TIA, Clément Share this post Link to post
Kas Ob. 124 Posted December 21, 2023 Hi, Well, while waiting for Angus or François to answer, i can give a few thoughts: 1) Ping is ICMP not UDP and not TCP. 2) There is no down side to use it at all, on the contrary most firewalls by default allowing it on local net (NAT) 3) You need the LAN subnet mask (aka range) and you can scan them, also no downside, but i am talking here about ICMP, and migt work for UDP too, in case UDP then it must be your own protocol/message. 4) If the devices you are looking for are running your application, then don't use ICMP, switch to UDP and broadcast, this will be faster and more accurate as your LAN router (or switch) will forward these on your behave, and your application on other devices can answer or just broadcast too. 5) there is ways to detect invisible devices (device with black hole firewall) and even know what system they are running, but this somewhat harder to implement in Delphi, you can test such functionality with nmap https://nmap.org/ https://github.com/nmap/nmap it is really fun to play with ! Share this post Link to post
Remy Lebeau 1436 Posted December 21, 2023 There is no such as a "TCP ping". Ping (ICMP) operates at a different protocol level than TCP. A ping can only tell you whether a machine/device is reachable on the LAN (assuming it even implements ICMP, and that ICMP is not being blocked by routers/firewalls, etc). But it cannot tell you whether there is an app actually listening on any TCP port on that machine/device. You would have to actually connect to a port to verify connectivity. That is what port scanners do. 1 Share this post Link to post
Angus Robertson 577 Posted December 21, 2023 As the others have said, TCP ping does not exist, you can try and open a specific TCP port at an IP address, but Windows has a long timeout while this is attempted and the socket can not be reused until that is over, so it's slow, and you need lots of parallel sockets to make it work, and hope some ports are open. Build the ICS Network Tools sample that got added to ICS V9, the LAN Devices tab uses a new component that scans ranges of IPv4 and IPv6 addresses for devices, using APR, Neighbourhood IPs and pings, and builds a table with host names, MAC addresses and vendor, etc. It's very similar to the excellent Nirsoft Wireless Network Watcher tool I've run continually for a decade to monitor my LAN. Angus Share this post Link to post
Clément 148 Posted December 26, 2023 On 12/21/2023 at 2:06 PM, Angus Robertson said: TCP ping does not exist, Yes I know. But this is how it's called. I managed to build a class where I can create a non-blocked socket connection with a timeout parameter. Usually the connection is pretty fast, and when the host doesn't exists, the timeout kicks in. But I'm afraid I don't know ICS internals to use a base ICS class. I still need to polish it. My first "ping" is way off... 8ms... when all other are below 1ms... Another thing, I'm not sure if there's something I can do about it, not all hosts can be "pinged". For example: I can ping "ICMP" 192.168.0.6 and there's a reply. If I ping "TCP" it returns not available host. My tcpPing class can ping any port, but by default it uses port 80. I m using vanilla winsock and winsock2. After some more tests I will post my code here. Share this post Link to post
Angus Robertson 577 Posted December 26, 2023 You have already discovered two reasons why TCP ping is unreliable, you need a remote open port and TCP timeouts are horrible to work around, that is why everyone uses ICMP ping which is 100 times more useful. If you want to persist with TCP (why???) you should be using the TIcsIpStrmLog component, with the OverbyteIcsIpStmLogTst sample, try to connect to your TCP address and port as TCP Client, there are various setting you can change. That component is used for similar purposes in other places in ICS, despite the name, it is really a high level version of WSocket that can be used as a client or server for TCP or UDP, sending data between instances of itself or other applications. Angus Share this post Link to post
Clément 148 Posted December 26, 2023 5 hours ago, Angus Robertson said: you want to persist with TCP (why???) For some devices a TCP connection is required, and I can send 1 or 2 bytes to trigger a response. In this case, for these devices, ICMP is disabled. dhsPinger allows to create a "device type" and choose the ping technology. You have the option to send bytes to trigger an answer. Share this post Link to post
Fr0sT.Brutal 900 Posted December 27, 2023 21 hours ago, Angus Robertson said: why??? He's doing it right testing both "device is up & software is listening" at the same time. 22 hours ago, Clément said: My first "ping" is way off... 8ms... when all other are below 1ms... Nice thing with async networking is that you can start many connections simultaneously and react for connection/timeout in event handlers. Share this post Link to post
Kas Ob. 124 Posted December 27, 2023 23 minutes ago, Fr0sT.Brutal said: 22 hours ago, Clément said: My first "ping" is way off... 8ms... when all other are below 1ms... Nice thing with async networking is that you can start many connections simultaneously and react for connection/timeout in event handlers. In fact, it is amazing it is 8ms not 50-200ms for TCP first packet, TCP have Nagle algorithm enabled by default, even with TCP_NODELAY enabled on the socket for the TCP, there is 3 ACK packet for establishing and connecting, which is unneeded for merely a ping simulation, or just checking for presence. I always send my ping (or keep alive on TCP or UDP) with current tick on the and measure against the response, this simplify the tracking for timeout, with this you have two mechanism to check one on pong and the other on background thread periodically checking (1/5 of the allowed timeout time ) for timeout, such thread is needed if IOCP is used, but otherwise i use the events on socket poll or the overlapped operation to trigger timeout from the last ping and mark the connection as down/lost. Again the best way to do it is with UDP and broadcasting on the broadcast IP for the network. Share this post Link to post
Angus Robertson 577 Posted December 27, 2023 Quote Nice thing with async networking is that you can start many connections simultaneously and react for connection/timeout in event handlers. Indeed, no need for threads in ICS. But Windows uses a thread to connect a TCP socket, and typically waits 30 to 40 seconds for a response before the Close event is called with an error, you can not abort it earlier. So the socket can not be re-used for another connection immediately, unlike ICMP. If you are checking a lot of hosts, you need a socket pool where they are not re-used until closed by Windows. Angus 1 Share this post Link to post