@@ -5,7 +5,10 @@ def is_valid_proxy(data):
55 """
66 check this string is within proxy format
77 """
8- if data .__contains__ (':' ):
8+ if is_auth_proxy (data ):
9+ host , port = extract_auth_proxy (data )
10+ return is_ip_valid (host ) and is_port_valid (port )
11+ elif data .__contains__ (':' ):
912 ip = data .split (':' )[0 ]
1013 port = data .split (':' )[1 ]
1114 return is_ip_valid (ip ) and is_port_valid (port )
@@ -17,6 +20,8 @@ def is_ip_valid(ip):
1720 """
1821 check this string is within ip format
1922 """
23+ if is_auth_proxy (ip ):
24+ ip = ip .split ('@' )[1 ]
2025 a = ip .split ('.' )
2126 if len (a ) != 4 :
2227 return False
@@ -48,9 +53,36 @@ def convert_proxy_or_proxies(data):
4853 # skip invalid item
4954 item = item .strip ()
5055 if not is_valid_proxy (item ): continue
51- host , port = item .split (':' )
56+ if is_auth_proxy (item ):
57+ host , port = extract_auth_proxy (item )
58+ else :
59+ host , port = item .split (':' )
5260 result .append (Proxy (host = host , port = int (port )))
5361 return result
5462 if isinstance (data , str ) and is_valid_proxy (data ):
55- host , port = data .split (':' )
63+ if is_auth_proxy (data ):
64+ host , port = extract_auth_proxy (data )
65+ else :
66+ host , port = data .split (':' )
5667 return Proxy (host = host , port = int (port ))
68+
69+
70+ def is_auth_proxy (data : str ) -> bool :
71+ return '@' in data
72+
73+
74+ def extract_auth_proxy (data : str ) -> (str , str ):
75+ """
76+ extract host and port from a proxy with authentication
77+ """
78+ auth = data .split ('@' )[0 ]
79+ ip_port = data .split ('@' )[1 ]
80+ ip = ip_port .split (':' )[0 ]
81+ port = ip_port .split (':' )[1 ]
82+ host = auth + '@' + ip
83+ return host , port
84+
85+
86+ if __name__ == '__main__' :
87+ proxy = 'test1234:test5678.@117.68.216.212:32425'
88+ print (extract_auth_proxy (proxy ))
0 commit comments