728x90
from stem.control import Controller
from stem import Signal
import time
import requests
proxies = {
'http':'socks5://127.0.0.1:9150',
'https':'socks5://127.0.0.1:9150'
}
# 지정할 국적을 입력
county_code = 'US'
ip_response = requests.get("http://ip-api.com/line", proxies=proxies)
ip_response.close()
for line in ip_response.content.decode("utf-8").split("\n"):
print(line)
controller = Controller.from_port(port = 9151)
controller.authenticate(password = "####")
# ExitNodes를 Tor에 사용하도록 지시
controller.set_conf('ExitNodes', '{' + county_code + '}')
controller.signal(Signal.NEWNYM)
time.sleep(5)
ip_response = requests.get("http://ip-api.com/line", proxies=proxies)
ip_response.close()
for line in ip_response.content.decode("utf-8").split("\n"):
print(line)