Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
'''
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