728x90
ํ์ฌ ํ์ด์ง์์ 42๋ฒ ํฌํธ๋ก ์ ์์ ํ๋ผ๊ณ ํ๋ค.
์๋์๋ ํ์ฌ ๋ด๊ฐ ์ ์ํ ํฌํธ ๋ฒํธ๊ฐ ์ ํ์์ผ๋ฉฐ ์ด๋ ๋งค๋ฒ ์๋ก ๊ณ ์นจ ํ ๋๋ง๋ค ๋ฐ๋ ์ ์๋ค.
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
class SourcePortAdapter(HTTPAdapter):
""""Transport adapter" that allows us to set the source port."""
def __init__(self, port, *args, **kwargs):
self._source_port = port
super(SourcePortAdapter, self).__init__(*args, **kwargs)
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, source_address=('', self._source_port))
s = requests.Session()
s.mount('http://', SourcePortAdapter(42))
s.mount('https://', SourcePortAdapter(42))
res = s.get("https://www.wechall.net/challenge/training/net/ports/index.php", cookies={"WC":"์์ ์_์ฟ ํค"})
print(res)
๋๊ตฐ๊ฐ ํ์ด์ฌ์ผ๋ก ์์ค ํฌํธ๋ฒํธ๋ฅผ ์ค์ ํ ์ ์๋ ์์ค ์ฝ๋๋ฅผ ์ฌ๋ฆฐ๊ฒ ์์ด์ ์ด๋ฅผ ์์ ํด์ ์ฌ์ฉํ๋ค.
์ถ์ฒ:
Python Requests, how to specify port for outgoing traffic?
I'm working on a project where we want to assign a whitelist packet filters for incoming traffic on a firewall and we are using python script with requests library to make some https requests to some
stackoverflow.com
728x90