Oh well, I suppose I'll write all this again, having lost it last time!
Can you help? I'm looking for a tool to do something rather specific and not finding much.
What I want is: a client machine needs to be able to make a TCP connection to any of several IP addresses on a pool of servers (it doesn't necessarily know which server has the IP address at the time) and the server should give it a count of connections to a specific port on that specific IP address.
The reason is to add a safety check to my VM start scripts - I want them to be able to poke the server hosting each volume the VM will connect to, to check how many iSCSI connections are active before letting the VM use the volume. Each iSCSI volume already has its own dedicated IPv6 address so that I can migrate volumes around without client VMs having to know where to connect. Also, for various reasons I don't think SCSI locks will be suitable.
My thinking so far is that I install an inetd-alike, listen on a port, and run a shell script. The script checks the local IP address of its stdin socket, uses ss or similar to count connections to the iSCSI port on that IP address, and outputs the number. Mostly easy, except finding the local IP address.
rlinetd (https://manpages.debian.org/bookworm/rlinetd/rlinetd.conf.5.en.html) has a substitution for the *remote* IP address, but not for the *local* address. xinetd (https://manpages.debian.org/bookworm/xinetd/xinetd.conf.5.en.html) doesn't look like it has either, from a quick skim.
If I could find a command line tool able to check the socket on stdin and output the local IP address, that would be great. It's hard to search for, though; the results seem flooded with how to get the local machine's IP address ("hostname -i"), how to get a remote machine's IP address ("dig"), or how to open a TCP socket in C.
I'd rather not write my own little tool as it'd probably take me far too many hours of frustratedly scouring documentation trying to find the right syscalls/library functions to do it. It's conceptually simple, it's discovery that's likely to be the problem. I might try digging into the Python networking documentation if I can't find anything else.
So, can you suggest anything? A CLI tool to just spit out the local IP address of the socket on stdin would be great, but alternative ideas are also helpful.
Thank you. :)