Skip to content

Instantly share code, notes, and snippets.

@Rhynorater
Created September 9, 2019 20:03
Show Gist options
  • Save Rhynorater/8ae9e59e5ee131f546d85348492ab535 to your computer and use it in GitHub Desktop.
Save Rhynorater/8ae9e59e5ee131f546d85348492ab535 to your computer and use it in GitHub Desktop.
Quickly rotating IPs to avoid ip ban using /64 ipv6 block.
import requests
from httplib import HTTPConnection
import socket
import subprocess
class MyHTTPConnection(HTTPConnection):
def connect(self):
self.sock = s
if self._tunnel_host:
self._tunnel()
def checkThings(things, ints):
first = True
int1,int2=ints
requests.packages.urllib3.connectionpool.HTTPConnection = MyHTTPConnection
result = False
pInt1,pInt2=-1,-1
for thing in things:
while True:
my_ip = (prefix+":{}:{}:"+postfix).format(hex(int1)[2:], hex(int2)[2:])#Format the IP address
my_ip = ":".join(map(lambda p: p.lstrip("0") if p.lstrip("0") != "" else "0", my_ip.split(":")))#"ip a" doesn't do :: only :0:
if pInt1 != int1 or pInt2 != int2:
output = subprocess.check_output(['ip', 'a'])#grab output from "ip a"
old_ip = (prefix+":{}:{}:00"+postfix).format(hex(pInt1)[2:], hex(pInt2)[2:])
old_ip = ":".join(map(lambda p: p.lstrip("0") if p.lstrip("0") != "" else "0", old_ip.split(":")))
triggerSleep = False
if old_ip+"/128" in output:#Check if the old ip is in the ip a, if it is, delete it
print "Deleteing old "+old_ip
print subprocess.check_output("ip -6 addr del {} dev eth0".format(old_ip).split())
triggerSleep = True
if my_ip+"/128" not in output: #Check if the new ip is in the ipa, if it isn't, add it
print "Adding new "+my_ip
print subprocess.check_output("ip -6 addr add {} dev eth0".format(my_ip).split())
triggerSleep = True
pInt1,pInt2=int1,int2
if triggerSleep: time.sleep(5)
print "Trying with ip {}".format(my_ip)
#Here is where the IPv6y stuff happens
l = socket.getaddrinfo(my_ip, None, 0, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)[0]
s = socket.socket(l[0], l[1], l[2]) # the "s" variable is used by MyHTTPConnection above which sets the socket for the requests library
s.bind(l[4]) #bind to the socket as defined by socket.getaddrinfo
s.connect(('ipv6.website.com', 443)) #connect to our target host
url = "https://ipv6.website.com"
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
data = {"yo": "define your request body here"}
x = requests.post(url, headers=headers, data=data)
#Do stuff with the response from the request
if 'your freaking banned - fool' in x.content:
print "Banned - rotate ip and retry"
if int2 < 65535:
int2 +=1
elif int2 >= 65535 and int2 < 65535:
int1 +=1
int2 = 0
else:
int1 = 0
int2 =0
elif 'YAAASSSS' in x.content:
print "Valid!: "+thing
result = thing
break
if result != False: break
return (result, ints)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment