Dup Ver Goto 📝

SimpleLookup1

PT2/lang/python/net does not exist
To
17 lines, 77 words, 543 chars Page 'SimpleLookup1' does not exist.

The main use here is when sending OSC messages using python-osc, it seems to work better if you use the numerical address for the target device. On my LAN I stick to IPV4, hence AF_INET and SOCK_DGRAM. Then info[0][4][0] drills down into the returned structure to find the IP address.

#!/usr/bin/env python
import socket
import sys
for arg in sys.argv[1:]:
  info = socket.getaddrinfo(arg,0,socket.AF_INET,socket.SOCK_DGRAM)
  if len(info) > 0:
    ip = info[0][4][0]
    print(ip)
  else:
    print(f"{arg}: Not found")