I formerly used the code below to bind IPv4 address to Python socket as source ip address.
import socket
true_socket = socket.socket
def bound_socket(*a, **k):
sock = true_socket(*a, **k)
sock.bind((sourceIP, 0))
return sock
socket.socket = bound_socket
Does above code work for IPv6 address? If not, how can I bind an IPv6 address?
Thanks in advance!
you can try this, to get an IPV6 address, it is recommend that you use
socket.getaddrinfoit will return all the different address both IPV4 and IPV6, you can bind them all or just which ever one you want/need.