Skip to content

Commit ccde736

Browse files
authored
feat: random header to avoid risk control
1 parent 4aef3e4 commit ccde736

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

api.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,9 @@ def hmac_sha256(key, message):
603603
"csrf": "",
604604
}
605605

606+
import random
606607
headers = {
607-
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0"
608+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),
608609
}
609610
resp = requests.post(url, params=params, headers=headers).json()
610611
return resp["data"]["ticket"]

geetest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ def validate(self, gt, challenge) -> str:
9191

9292

9393
if __name__ == "__main__":
94+
import random
9495
captcha = requests.get(
9596
"https://passport.bilibili.com/x/passport-login/captcha", headers={
96-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0"
97+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),
9798
}
9899
).json()
99100
gt = captcha["data"]["geetest"]["gt"]

globals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ def load_config():
283283
while True:
284284
if "cookie" not in config or not use_login:
285285
config["cookie"] = interactive_login(sentry_sdk)
286+
import random
286287
headers = {
287-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0",
288+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),
288289
"Cookie": config["cookie"],
289290
}
290291
user = requests.get(

login.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ def interactive_login(sentry_sdk=None):
463463
#from globals import i18n_lang
464464
global sdk
465465
sdk = sentry_sdk
466+
import random
466467
headers = {
467-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0"
468+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),
468469
}
469470

470471
session = requests.session()

main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ def main():
125125
config = load_config()
126126
if config == None:
127127
return
128+
import random
128129
headers = {
129-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0",
130+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),,
130131
"Cookie": config["cookie"],
131132
}
132133
if "user-agent" in config:

utility.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def captcha_mode(config):
132132
else:
133133
logger.error(i18n_gt()["captcha_mode_not_supported"])
134134
save(config)
135-
135+
import random
136136
headers = {
137137
"Cookie": config["cookie"],
138-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0",
138+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/618.1.15.10.15 (KHTML, like Gecko) Mobile/21F90 BiliApp/77900100 os/ios model/iPhone 15 mobi_app/iphone build/77900100 osVer/17.5.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CH disable_rcmd/0 "+str(random.randint(0, 9999)),,
139139
"Referer": "https://show.bilibili.com"
140140
}
141141
select = prompt([

0 commit comments

Comments
 (0)