如何从 aiohttp 响应中获取 IP 地址 [英] How to get IP address from aiohttp response

查看:30
本文介绍了如何从 aiohttp 响应中获取 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试查看来自 aiohttp 请求的响应,但没有找到获取指定主机 ip 地址的方法:

I am have been trying to look into responses from aiohttp requests and have not found a way to get the ipaddress of the specified host:

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

推荐答案

我假设您的主机由一个 url 表示(否则您已经拥有 IP)

I assume your host is represented by a url (otherwise you already have the IP)

所以你需要做的是通过url获取IP地址.
您可以通过以下方式执行此操作:

So what you need to do is get an ip address by url.
You can do this by:

import socket
print socket.gethostbyname('your hosto name')

您的主机名可能是http://{host}"

your host name is probably 'http://{host}'

这篇关于如何从 aiohttp 响应中获取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆