File size: 571 Bytes
4db7b7b
 
b56f564
 
 
4db7b7b
1dafb9b
48928d8
 
 
 
4db7b7b
b56f564
4db7b7b
b56f564
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import socket

def patch_dns():
    print("[DNS FIX] Patching socket.getaddrinfo to force IPv4 resolution...")
    _orig_getaddrinfo = socket.getaddrinfo

    def new_getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
        # Force AF_INET (IPv4) resolution except for localhost
        if host and host not in ('localhost', '127.0.0.1', '::1'):
            return _orig_getaddrinfo(host, port, socket.AF_INET, type, proto, flags)
        return _orig_getaddrinfo(host, port, family, type, proto, flags)

    socket.getaddrinfo = new_getaddrinfo

patch_dns()