![]() |
|
Simple Proxy Checker - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Python (https://sinister.li/Forum-Python) +--- Thread: Simple Proxy Checker (/Thread-Simple-Proxy-Checker) |
Simple Proxy Checker - Leviathan - 08-18-2019 Hey there, I made a simple proxy checker in Python. Save the proxies like that in the proxylist.txt: Code: IP:PORTSpoiler:Code: import socket
import os.path
class ProxyChecker():
def __init__(self):
print("Starting the checker...")
def CheckProxy(self):
try:
with open('proxylist.txt', 'r+') as f:
for line in f.readlines():
ipAddress = str.split(line, ':')[0]
port = str.split(line, ':')[1]
proxyIP = (ipAddress, int(port))
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
s.settimeout(5)
print("[!] - Checking {} ...".format(proxyIP))
if s.connect_ex(proxyIP):
pass
else:
self.AddProxy(ipAddress + ":" + str(port))
except IOError:
print('proxylist.txt not found')
def AddProxy(self, proxyAddress):
with open('positive.txt', 'a') as f:
#Duplicate Check:
with open('positive.txt', 'r+') as r:
if proxyAddress in r.readlines():
print("[!] - {} already added!".format(proxyAddress))
else:
print("[+] - {} added!".format(proxyAddress))
f.write(proxyAddress)
if __name__ == "__main__":
ProxyChecker().CheckProxy()RE: Simple Proxy Checker - Oliver45U - 01-22-2021 Learn this language by myself or take courses? RE: Simple Proxy Checker - DedSpace - 02-10-2021 (01-22-2021, 07:07 PM)Oliver45U Wrote: Learn this language by myself or take courses? Python is a very simple language and a very good place to start your coding journey. There are plenty of online resources including hackerrank.com where you can learn for free without having to install python on your pc. I do suggest you download Visual Studio Code to use as your IDE as the debugging is very good. RE: Simple Proxy Checker - DedSpace - 02-10-2021 (08-18-2019, 08:47 AM)Leviathan Wrote: Hey there, I made a simple proxy checker in Python. Hi. I like your script and thought it could do with some more functionality. It now allows users to specify input file name, output file name, verbosity, and timeout with default value of 2s. If a proxy server takes more than 2 seconds to reply it's not worth using. I also added the shebang so just run "./scriptname -h" to get the help message up (Linux only). Also, put it in /bin/ so you can just run "scriptname" from anywhere. Again, Linux only. Code: #! /usr/bin/python3
import socket
import os.path
import argparse as arg
class ProxyChecker():
def __init__(self):
print("Starting the checker...")
def CheckProxy(self, file, timeout, verbose, output):
try:
with open(file, 'r') as f:
for line in f.readlines():
ipAddress = str.split(line, ':')[0]
port = str.split(line, ':')[1]
proxyIP = (ipAddress, int(port))
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
s.settimeout(timeout)
if verbose:
print("[!] - Checking {} ...".format(proxyIP))
if s.connect_ex(proxyIP):
pass
else:
self.AddProxy(ipAddress + ":" + str(port), verbose, output)
except IOError:
print(file + ' not found')
def AddProxy(self, proxyAddress, verbose, output):
with open(output, 'a') as f:
#Duplicate Check:
with open(output, 'r+') as r:
if proxyAddress in r.readlines():
if verbose:
print("[!] - {} already added!".format(proxyAddress))
else:
if verbose:
print("[+] - {} added!".format(proxyAddress))
f.write(proxyAddress)
def main():
parser = arg.ArgumentParser()
parser.add_argument("--file", "-f", type=str, required=True,
help="File to check.")
parser.add_argument("--timeout", "-t", type=int, default=2,
help="Integer time out value, default value is 2 seconds.")
parser.add_argument("--output", "-o", default="positive.txt",
help="Output filename, default is 'positive.txt'")
parser.add_argument("--verbose", "-v", default=False, action="store_true",
help="Print proxies as they are checked and added.")
args = parser.parse_args()
file = args.file
timeout = args.timeout
verbose = args.verbose
output = args.output
ProxyChecker().CheckProxy(file, timeout, verbose, output)
print("Done!")
if __name__ == "__main__":
main() |