Python3 code to display hostname and IP address

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"

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

时间: 2024-08-30 12:17:33

Python3 code to display hostname and IP address的相关文章

live555 出现Unable to determine our source address: This computer has an invalid IP address: 0.0.0.0 的解决方案。

网上的方案我没有使用.对于只有一个网卡的主机来说,它的ip只有一个.可用shell命令获取到这个ip. 官方的live555的live/groupsock/GroupsockHelper.cpp里面的函数ourIPAddress如下: 1 netAddressBits ourIPAddress(UsageEnvironment& env) { 2 static netAddressBits ourAddress = 0; 3 int sock = -1; 4 struct in_addr tes

Oracle 安装报错 [INS-06101] IP address of localhost could not be determined 解决方法

出现这种错误是因为主机名和/etc/hosts 文件不一致,只需要把主机名和其IP 写入/etc/hosts 文件,就ok了. 注意名字不能有下划线 修改network 文件之外,再使用hostname 命令指定一下主机名,就不用重启OS了. 1.     修改/etc/sysconfig/network 文件 [[email protected]~]# cat /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=s

IP address could not be resolved: Temporary failure in name resolution

今早发现mysql日志中有非常多例如以下的警告: 140724 18:41:25 [Warning] IP address '172.16.18.217' could not be resolved: Temporary failure in name resolution 140724 18:41:25 [Warning] IP address '172.16.18.217' could not be resolved: Temporary failure in name resolution

MySql连接错误:Can't get hostname for your address

简单解释 MySQL server received a request from you to allow you to connect to the database. So next thing it tried to do is to check what name is bound to your IP address (name resolution) and it failed to do so. So it just denied you access. 可以这么理解mysql处

Oracle 安装报错 [INS-06101] IP address of localhost could not be determined 解决方法输入日志标题

安装Oracle 11gR2,报错:[INS-06101] IP address of localhost could not be determined 出现这种错误是因为主机名和/etc/hosts 文件不一致,只需要把主机名和其IP 写入/etc/hosts 文件,就ok了. 查看主机名和和ip 地址关系: [[email protected]~]# cat /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=

【资料整理】cisco [OSI, IP Address, Network Segment, Subnet Mask]

### Concept ### ---------------------- from 20110712 to 20110716 1.Network segment { router; switch; bridge; } 2.LAN blocks { broadcast domain; broadcast  storm; multicast; low brandwidth; } 3.benefits of the router { ! forward broadcast; filter msgs

dubbo could not get local host ip address will use 127.0.0.1 instead 异常处理

dubbo could not get local host ip address will use 127.0.0.1 instead 查看hostname 修改hosts文件 vi /etc/hosts 前:内网IP  后:hostname 原文地址:https://www.cnblogs.com/anong/p/9447957.html

Get the client's IP address in socket.io

From: https://www.wentong.org/codex/question-2018081564702.html When using socket.IO in a Node.js server, is there an easy way to get the IP address of an incoming connection? I know you can get it from a standard HTTP connection, but socket.io is a

The ip address is being used by a static-MAC user

解决华为路由器在vlan中静态地址绑定出现"The ip address is being used by a static-MAC user"的问题 故障原因:该mac地址已经通过dhcp分配了ip 查看vlan里分配的ip display ip pool interface Vlanif10 all | include xxx-xxxx-xxxx 假设查询结果为192.168.1.200 清除绑定的ip ****注意此操作要在用户模式下 reset ip pool interfac