Skip to content

Instantly share code, notes, and snippets.

@StephanieSunshine
Created November 21, 2021 15:32
Show Gist options
  • Save StephanieSunshine/4a725beb54ee67d15d30513593cb73d2 to your computer and use it in GitHub Desktop.
Save StephanieSunshine/4a725beb54ee67d15d30513593cb73d2 to your computer and use it in GitHub Desktop.
Get client and server ip and port from openbsd-inetd/tcpd
#!/usr/bin/python3
# pytcpd.py
#
# get server ip:port and client ip:port from openbsd-inetd/tcpd
# this can be used as the start of a nowait tcp daemon that needs to be aware
# of the underlying network
#
# Stephanie Sunshine 2021 -- MIT License
import sys
import socket
# socket.AF_INET6 for IPV6
# socket.SOCK_DGRAM for UDP
sock = socket.fromfd(sys.stdin.fileno(), socket.AF_INET, socket.SOCK_STREAM)
print(f"connected: {sock.getpeername()} => {sock.getsockname()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment