-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathexample4 - network_and_security.py
More file actions
65 lines (56 loc) · 1.89 KB
/
Copy pathexample4 - network_and_security.py
File metadata and controls
65 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import asyncio
import noble_tls
from noble_tls import Client
async def main():
await noble_tls.update_if_necessary()
# IPv4-only with local address binding (host:port, use port 0 for auto)
session = noble_tls.Session(
client=Client.CHROME_133_PSK,
disable_ipv6=True,
local_address="0.0.0.0:0",
)
res = await session.get(
"https://tls.peet.ws/api/all",
insecure_skip_verify=True,
)
print(f"Status: {res.status_code}")
print(f"Protocol: {res.used_protocol}")
await session.close()
# Certificate pinning — rejects unless the SHA256 pin matches
pinned = noble_tls.Session(
client=Client.CHROME_133,
certificate_pinning={
"tls.peet.ws": [
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
],
},
)
try:
await pinned.get("https://tls.peet.ws/api/all")
except Exception as e:
print(f"Pinning rejected (expected with fake pin): {e}")
await pinned.close()
# Rotating proxy — forces a new connection per request
proxy_session = noble_tls.Session(
client=Client.FIREFOX_135,
is_rotating_proxy=True,
)
proxy_session.proxies = {"http": "http://user:pass@proxy.example.com:8080"}
try:
await proxy_session.get("https://tls.peet.ws/api/all", timeout_milliseconds=5000)
except Exception as e:
print(f"Proxy request failed (expected without real proxy): {e}")
await proxy_session.close()
# Host header override + SNI override
direct = noble_tls.Session(
client=Client.CHROME_131,
server_name_overwrite="tls.peet.ws",
)
res = await direct.get(
"https://tls.peet.ws/api/all",
request_host_override="custom.host.example.com",
)
print(f"Status: {res.status_code}")
print(f"Protocol: {res.used_protocol}")
await direct.close()
asyncio.run(main())