If you have ever used the internet superserver inetd and connected it to a bash script and wondered how to retrieve the ip and port of the client, here is the solution:
/etc/inetd.conf
666 stream tcp nowait root /opt/client_ip.sh
Maybe you need to apt-get install tcputils to install getpeername.
/etc/inetd.conf
666 stream tcp nowait root /opt/client_ip.sh
/opt/client_ip.sh
#!/bin/bash
read ip port <<< `getpeername`
# $ip now contains the ip
# $port now contains the port
Maybe you need to apt-get install tcputils to install getpeername.
Keine Kommentare:
Kommentar veröffentlichen