Created
November 21, 2021 15:32
-
-
Save StephanieSunshine/4a725beb54ee67d15d30513593cb73d2 to your computer and use it in GitHub Desktop.
Get client and server ip and port from openbsd-inetd/tcpd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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