python在Windows8下获取本机ip地址的方法_python

本文实例讲述了python在Windows8下获取本机ip地址的方法。分享给大家供大家参考。具体实现方法如下:

import socket
hostname = socket.gethostname()
IPinfo = socket.gethostbyname_ex(hostname)
LocalIP = IPinfo[2][2]
print LocalIP

希望本文所述对大家的Python程序设计有所帮助。

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索python
, 方法
, ip地址
, windows8
, 获取
本机
python 获取ip地址、python获取网卡ip地址、python获取本机ip地址、python3 获取ip地址、windows获取ip地址,以便于您获取更多的相关知识。

时间: 2024-09-18 21:35:17

python在Windows8下获取本机ip地址的方法_python的相关文章

Python获取Linux系统下的本机IP地址代码分享_python

有时候使用到获取本机IP,就采用以下方式进行. 复制代码 代码如下: #!/usr/bin/python   import socket import struct import fcntl   def getip(ethname):   s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)   return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0X8915, struct.pack('256s', e

python基础教程之获取本机ip数据包示例_python

这几天用到了raw socket,用python写了些demo程序,这里记录下. 首先我们看一个简单的sniffer程序: 复制代码 代码如下: #! /usr/bin/python# code for linuximport socket#s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.I

python获取外网ip地址的方法总结

  本文实例总结了python获取外网ip地址的方法.分享给大家供大家参考.具体如下: 一.利用脚本引擎库直接获取 ? 1 2 3 4 5 6 7 import console; import web.script import inet.http; var jsVm = web.script("JavaScript") jsVm.AddCode( inet.http().get("http://fw.qq.com/ipaddress") ) var ipAddr

Qt 5.7 获取本机IP地址

Qt 获取本机IP地址 最先想到的方案 QString get_local_ip() { QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName()); // 找出一个IPv4地址即返回 foreach(QHostAddress address,info.addresses()) { if(address.protocol() == QAbstractSocket::IPv4Protocol) { return address.

Linux在命令行下列出本机IP地址,而不是得到网卡信息

Linux在命令行下列出本机IP地址,而不是得到网卡信息 ifconfig | grep "inet" | cut -c 0-36 | sed -e 's/[a-zA-Z: ]//g'hosthttp://www.aliyun.com/zixun/aggregation/11696.html">name - i

python实现根据主机名字获得所有ip地址的方法

  本文实例讲述了python实现根据主机名字获得所有ip地址的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 # -*- coding: utf-8 -*- import sys, socket result = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM) counter = 0 for item in result: print "%-2d: %s" % (cou

XP系统获取未使用IP地址的方法

XP系统获取未使用IP地址的方法   解决方法: 打开记事本,在窗口中输入如下的命令: @Echooff date/t>IPList.txt time/t>>IPList.txt echo===========>>IPList.txt For/L%%fin(1,1,100)DoPing.exe-n2192.168.1.%%f|Find "Requesttimedout."&&echo192.168.1.%%fTimedOut>>

Delphi 7中快速获取本机IP地址

朋友们在用Delphi编程序的时候,常常碰到需要在程序中获取自己的IP地址的情况.在以往的版本中,可以通过编写一段代码或函数实现这一功能.但有了Delphi 7,这个工作可以更简化了.利用控件只需一句代码,就可以非常方便地实现这一功能. 新建一Project1,在form1中添加控件statusbar1(Win32页)和控件IdIPWatch1(Indy Misc页).接着设置好控件属性:在statusbar1的panels中添加0-TStatusPanel和1-TStatusPanel两项:I

asp.net中c#获取本机IP地址实例代码

例1  代码如下 复制代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace CSharpTest {     class Program     {         static void Main(string[] args)         {             Console.Write(new Progr