码迷,mamicode.com
首页 > 编程语言 > 详细

Python3 code to display hostname and IP address

时间:2019-10-21 18:58:18      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:usr   window   div   address   col   display   sock   and   hostname   

OS: Windows 7

#!/usr/bin/env python3

# Python3 code to display hostname and 
# IP address 

# Importing socket library 
import socket 

# Function to display hostname and 
# IP address 
def get_Host_name_IP(): 
    try: 
        host_name = socket.gethostname() 
        host_ip = socket.gethostbyname(host_name) 
        print("Hostname :  ",host_name) 
        print("IP : ",host_ip) 
    except: 
        print("Unable to get Hostname and IP") 

# Driver code 
get_Host_name_IP() #Function call 

#This code is conributed by "Sharad_Bhardwaj"

 

Python3 code to display hostname and IP address

标签:usr   window   div   address   col   display   sock   and   hostname   

原文地址:https://www.cnblogs.com/python-abc/p/11715146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!