import requests
url = 'https://ya.ru'
# Замените 'your_ipv6_address' на реальный IPv6-адрес, который вы хотите использовать
ipv6_address = 'your_ipv6_address'
# Создаем заголовок с указанием IPv6-адреса
headers = {'Host': url, 'User-Agent': 'Your User Agent', 'Connection': 'keep-alive', 'Accept': '*/*', 'X-Forwarded-For': ipv6_address}
# Отправляем запрос с заданным заголовком
response = requests.get(url, headers=headers)
if response.status_code == 200:
print('Запрос успешно выполнен!')
print('Ответ от сервера:')
print(response.text)
else:
print(f'Ошибка при выполнении запроса. Код состояния: {response.status_code}')
import aiohttp
import asyncio
import socket
async def main(loop):
url = 'http://ip6only.me/'
conn = aiohttp.TCPConnector(family=socket.AF_INET6)
async with aiohttp.ClientSession(connector=conn) as session:
async with session.get(url) as resp:
if resp.status == 200:
print('Запрос успешно выполнен!')
print('Ответ от сервера:')
# выводим сайт в текстом
html = await resp.text()
print("Body:", html[:500], "...")
else:
print(f'Ошибка при выполнении запроса. Код состояния: {resp.status}')
await resp.release()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()
import requests
from requests_toolbelt.adapters import source
source = source.SourceAddressAdapter('1a01:1f00:0:1::108f')
with requests.Session() as session:
session.mount('http://', source)
r = session.get("http://ip6only.me/")
if r.status_code == 200:
print('Запрос успешно выполнен!')
print('Ответ от сервера:')
print(r.text)
else:
print(f'Ошибка при выполнении запроса. Код состояния: {r.status_code}')
class MyLogger:
def __init__(self):
self.logger = logger
# Clear all settings
self.logger.remove()
# Add the format of the console output, sys.stdout is output to the screen; regarding these configurations, you need to customize the official website to view the relevant parameter description
self.logger.add(sys.stdout,
format="<white>{time:YYYY.MM.DD HH:mm:ss}</white> | " # > Time
"{process.name} | " # Process Name
"<cyan>{module}</cyan>.<cyan>{function}</cyan>" # Module name. Method name
":<cyan>{line}</cyan> | "
"<level>{level}</level> | "
"<level>{message}</level>",
)
def get_logger(self):
return self.logger
my_logger = MyLogger().get_logger()