Skip to content

Instantly share code, notes, and snippets.

@rgov
Created March 27, 2018 16:33
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rgov/86cdc1ae0e2b02c665c2f76c8e83b38e to your computer and use it in GitHub Desktop.
'''
Use the IP_BOUND_IF socket option to bind to a specific network interface on macOS.
'''
import socket
IP_BOUND_IF = 25
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_IP, IP_BOUND_IF, socket.if_nametoindex('en0'))
s.connect(("151.101.193.67" , 80))
s.sendall(b"GET / HTTP/1.1\r\nHost: www.cnn.com\r\n\r\n")
print(s.recv(4096))
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment