我一直在尝试研究来自aiohttp请求的响应,但是还没有找到获取指定主机的ipaddress的方法:
async with aiohttp.ClientSession() as session:
async with session.get(f'http://{host}') as response:
print(response.__dir__())
#Wanting to get ipaddress of response right here
答案 0 :(得分:2)
我假设您的主机由一个url表示(否则您已经拥有IP)
所以您需要做的是通过url获取IP地址。
您可以通过以下方式做到这一点:
import socket
print socket.gethostbyname('your hosto name')
您的主机名可能是“ http:// {host}”