# -*- coding: utf-8 -*- """ @Author: Meng @software: PyCharm @file: python获取计算机名IP用户名.py @time: 2021/10/28 20:44 """ import socket import getpass # 获取当前获取计算机名称 hostname = socket.gethostname() # 获取本机IP pcname = socket.gethostname() # 获取计算机名 username = getpass.getuser() # 获取当前用户名 ip = socket.gethostbyname(hostname) print(username,ip,pcname)