使用Python获取IP地址可以使用socket库中的gethostname()函数和gethostbyname()函数。

import socket


def get_ip_address():
    hostname = socket.gethostname()
    ip_address = socket.gethostbyname(hostname)
    return ip_address


ip = get_ip_address()
print("IP地址:", ip)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注