Advertisement
rfmonk

getaddrinfo_basic_usage.notes

Jan 25th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. >>> from socket import getaddrinfo
  2. >>> getaddrinfo(None, 'smtp', 0, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
  3. Traceback (most recent call last):
  4. File "<input>", line 1, in <module>
  5. NameError: name 'socket' is not defined
  6. >>> import socket
  7. >>> getaddrinfo(None, 'smtp', 0, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
  8. [(2, 1, 6, '', ('0.0.0.0', 25)), (10, 1, 6, '', ('::', 25, 0, 0))]
  9. >>> getaddrinfo(None, 53, 0, socket.SOCK_DGRAM, 0, socket.AI_PASSIVE)
  10. [(2, 2, 17, '', ('0.0.0.0', 53)), (10, 2, 17, '', ('::', 53, 0, 0))]
  11. >>>
  12. >>> getaddrinfo('127.0.0.1', 'smtp', 0, socket.SOCK_STREAM, 0)
  13. [(2, 1, 6, '', ('127.0.0.1', 25))]
  14. >>> getaddrinfo('localhost', 'smtp', 0, socket.SOCK_STREAM, 0)
  15. [(10, 1, 6, '', ('::1', 25, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 25))]
  16. >>>
  17. #++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. >>> getaddrinfo('ftp.kernel.org', 'ftp', 0, socket.SOCK_STREAM, 0, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
  19. [(2, 1, 6, '', ('198.145.20.140', 21)), (2, 1, 6, '', ('199.204.44.194', 21)), (2, 1, 6, '', ('149.20.4.69', 21))]
  20. >>> getaddrinfo('iana.org', 'www', 0, socket.SOCK_STREAM, 0, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
  21. [(2, 1, 6, '', ('192.0.43.8', 80)), (10, 1, 6, '', ('2001:500:88:200::8', 80, 0, 0))]
  22. >>> getaddrinfo('iana.org', 'www', 0, socket.SOCK_STREAM, 0)
  23. [(2, 1, 6, '', ('192.0.43.8', 80)), (10, 1, 6, '', ('2001:500:88:200::8', 80, 0, 0))]
  24. >>> getaddrinfo('iana.org', 'www', 0, socket.SOCK_STREAM, 0, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED | socket.AI_CANONNAME)
  25. [(2, 1, 6, 'iana.org', ('192.0.43.8', 80)), (10, 1, 6, '', ('2001:500:88:200::8', 80, 0, 0))]
  26. >>> mysock = old_sock.accept()
  27. Traceback (most recent call last):
  28. File "<input>", line 1, in <module>
  29. NameError: name 'old_sock' is not defined
  30. >>> socket.gethostname()
  31. 'nsa'
  32. >>> socket.getfqdn()
  33. 'nsa.fuckyou.mil'
  34. >>> socket.gethostbyname('cern.ch')
  35. '137.138.144.169'
  36. >>> socket.gethostbyaddr('137.138.144.169')
  37. ('webr8.cern.ch', [], ['137.138.144.169'])
  38. >>> socket.getprotobyname('UDP')
  39. 17
  40. >>> socket.getservbyname('www')
  41. 80
  42. >>> socket.getservbyport(80)
  43. 'http'
  44. >>> socket.gethostbyname(socket.getfqdn())
  45. '137.138.144.169'
  46. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement