4g huawei dongle automated script to close open data connection to get new IP

Wrote this and thought it might help someone, gets a new IP every 30mins, you need python & selenium & chrome webdriver, run alongside JV.

# change IP every so many seconds. 1800 seconds is 30 mins.
# it uses selenium to click the data off then back on, then shows the new ip address through the proxy server

from selenium import webdriver
import time
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry


s = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
s.mount('http://', adapter)
s.mount('https://', adapter)


while True:
    try:
        browser = webdriver.Chrome('/instagramapi/chromedriver.exe')
        browser.get('http://192.168.8.1/html/mobileconnection.html')
        button = browser.find_element_by_id('mobilenetwork_turnOff_button')
        button.click()
        time.sleep(5)
        button = browser.find_element_by_id('mobilenetwork_turnOn_button')
        button.click()
        time.sleep(5)
        browser.quit()
        time.sleep(20)
        r = s.get("http://www.alloys.xyz/ip.asp", proxies={'http': 'http://192.168.8.100:808'})
        print(r.text)
        time.sleep(1800)

    except Exception as e:
        print("Restarted as error in script " + str(e))
12 Likes

Trying it on my linux server. really appreciate your effort man.

This wont work with networks which are true LTE. ( Like Jio - India ), Normally IP doesn’t changes when we manually turn on & off mobile data.
IP changes when we turn on “flight-mode”.
so only “device reboot” works in our case.

1 Like

All you need to do is replace the page and replace the button ID in the code with the reboot ID. And you can reboot instead.

2 Likes

after we click “reboot” another confirmation dialog appears.

Btw i am a noob with selenium. just started researching after looking your code. haha

1 Like

the id for that is pop_confirm :grinning:

button = browser.find_element_by_id(‘pop_confirm’)
button.click()

3 Likes

Example below,

C:\InstagramAPI>python 4g.py

DevTools listening on ws://127.0.0.1:50945/devtools/browser/4255321b-c9d1-4b17-b3e3-ce59c38dde1f
188.34.164.91

DevTools listening on ws://127.0.0.1:51888/devtools/browser/f154cb1d-4fd1-4bc3-ba62-5b33e77ff182
96.197.88.153

DevTools listening on ws://127.0.0.1:52780/devtools/browser/2d3271be-8c01-498d-a56d-030b27bc4a2c
96.197.43.24

DevTools listening on ws://127.0.0.1:53608/devtools/browser/b1893f12-83cf-48a7-874f-3c49e92c8b3a
91.45.3.162

2 Likes

That’s interesting. Is it working if you do it via a VM like virtual box for example? The script is still able to target the right USB where you have the dongle attached for having internet via dongle only in VM instance?

So the python script just sits and runs forever on the server. The http://192.168.8.1/html/mobileconnection.html is this, the selenium script is just opening up a browser and pressing that button; As I add more accounts to the 4g connection, im going to decrease the time in my script, that’s my plan.

I have 10 account so far, and they are all following/unfollowing/liking/messaging on JV and LE yesterday, 25/07/19 I used 814.72 MB!

I did try having the auto disconnect set low but the IP didn’t seem to change very often.

3 Likes

Thanks for the code brother!

1 Like

I have no clue what’s going on here :sweat_smile:

what is the purpose of this? because a normal phone doesnt do this right?

you saved my life !!! my head was exploding :smiley: all i needed was a reboot. omg appreciate it mate !!

Thank you so much bro! I was killing myself , why 3g works fine, but 4g rotation is not. Reboot !!! genius !!! <3

Let me know if you can manage to write code for reboot.
Because i failed. Haha

1 Like

Do you want it to also reboot other dongles by proxy? :+1:

1 Like

@SatyAjit

    browser.get('http://192.168.8.1/html/reboot.html')
    button = browser.find_element_by_id('undefined')
    button.click()
    button = browser.find_element_by_id('pop_confirm')
    button.click()
2 Likes

This version allows you to change a specific dongle via a proxy

https://www.web-pros.co.uk/chromesafe.zip <<< you need a specific version of chrome.

from selenium import webdriver
import time
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from random import randint

PROXY = "192.168.8.101:808" # IP:PORT or HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

s = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
s.mount('http://', adapter)
s.mount('https://', adapter)

while True:
    try:        
        browser = webdriver.Chrome(executable_path='C:/instagramapi/chromesafe.exe',options = chrome_options)
        browser.get('http://192.168.8.1/html/reboot.html')
        button = browser.find_element_by_id('undefined')
        button.click()
        button = browser.find_element_by_id('pop_confirm')
        button.click()
        time.sleep(60)
        #browser.get('http://192.168.8.1/html/mobileconnection.html')
        #button = browser.find_element_by_id('mobilenetwork_turnOff_button')
        #button.click()
        #time.sleep(5)
        #button = browser.find_element_by_id('mobilenetwork_turnOn_button')
        #button.click()
        #time.sleep(5)
         
        browser.quit()
        time.sleep(60)
        r = s.get("https://www.web-pros.co.uk/ip.asp", proxies={'https': PROXY})
        print(r.text)
        time.sleep(randint(1200,2400))

    except Exception as e:
        print("Restarted as error in script " + str(e))
1 Like

This is very specific to the router model, did I understand correctly?

I have a Linux machine.It did work. Now i can use not only 3g , but 4G !!! :)))))))

MODEM_IP=“111.111.1111”
curl -s -X GET “http://$MODEM_IP/api/webserver/SesTokInfo” > ses_tokUSB_01.xml
COOKIE=grep "SessionID=" ses_tokUSB_01.xml | cut -b 10-147
TOKEN=grep "TokInfo" ses_tokUSB_01.xml | cut -b 10-41
curl -X POST -d @networktype-auto.txt “http://$MODEM_IP/api/net/net-mode”
-H “Cookie: $COOKIE” -H “__RequestVerificationToken: $TOKEN”
-H “Content-Type: text/xml” > /dev/null
sleep 5
curl -s -X GET “http://$MODEM_IP/api/webserver/SesTokInfo” > ses_tokUSB_01.xml
COOKIE=grep "SessionID=" ses_tokUSB_01.xml | cut -b 10-147
TOKEN=grep "TokInfo" ses_tokUSB_01.xml | cut -b 10-41
curl -X POST -d @reboot.txt “http://$MODEM_IP/api/device/control”
-H “Cookie: $COOKIE” -H “__RequestVerificationToken: $TOKEN”
-H “Content-Type: text/xml” > /dev/null
echo “IP Rotation: DONE”

file reboot.txt

<?xml version=\"1.0\" encoding=\"UTF-8\"?>1