Reputation: 1487
I have this script that simply uses a list of socks and tries to connect to a host. But it always shows this error:
File "*.py", line 38, in requestsocks
s.connect((host, port))
File "/home/*/.local/lib/python3.5/site-packages/socks.py", line 729, in connect
_BaseSocket.connect(self, proxy_addr)
TypeError: an integer is required (got type str)
Here is the code:
import socket,socks,random
def checkurl():
global url
global url2
global urlport
url = input("Insert URL: ")
if url[0]+url[1]+url[2]+url[3] == "www.":
url = "http://" + url
elif url[0]+url[1]+url[2]+url[3] == "http":
pass
else:
url = "http://" + url
try:
url2 = url.replace("http://", "").replace("https://", "").split('/')[0].split(":")[0]
except:
url2 = url.replace("http://", "").replace("https://", "").split('/')[0]
try:
urlport = url.replace("http://", "").replace("https://", "").split('/')[0].split(':')[1]
except:
urlport = "80"
def proxylist():
global entries
out_file = str(input("Enter the proxy list: "))
entries = open(out_file).readlines()
requestsocks()
def requestsocks():
while True:
proxy = random.choice(entries).strip().split(':')
host = str(url2)
port = int(urlport)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy[0], proxy[1], True)
s = socks.socksocket()
s.connect((host, port))
s.sendall('Hello world')
checkurl()
proxylist()
I don't know how can I solve this. Ideas? P.S. I've taken the socks list from here: https://www.socks-proxy.net/
Upvotes: 0
Views: 821
Reputation: 2183
I haven't done much with the sockets library, but it's asking for an integer for both host and port. Try getting the IP like this.
Add this ------> host = socket.gethostbyname(host)
def requestsocks():
while True:
proxy = random.choice(entries).strip().split(':')
host = str(url2)
# convert url to IP address
host = socket.gethostbyname(host)
port = int(urlport)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy[0], proxy[1], True)
s = socks.socksocket()
s.connect((host, port))
s.sendall('Hello world')
Upvotes: 1