Python获取Linux系统下的本机IP地址代码分享
作者:junjie 时间:2021-07-23 00:26:22
有时候使用到获取本机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', ethname[:15]))[20:24])
if __name__=='__main__':
print getip('eth0')
标签:Python,Linux,本机IP地址
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何用python绘制雷达图
2023-04-19 12:44:09
![](https://img.aspxhome.com/file/2023/4/78544_0s.jpg)
php随机取mysql记录方法小结
2023-11-22 22:27:22
Pytorch关于Dataset 的数据处理
2021-04-16 08:40:54
![](https://img.aspxhome.com/file/2023/1/84901_0s.png)
微信跳一跳游戏python脚本
2022-03-31 02:24:27
![](https://img.aspxhome.com/file/2023/6/66806_0s.jpg)
Flask交互基础(GET、 POST 、PUT、 DELETE)的使用
2022-01-17 11:00:04
![](https://img.aspxhome.com/file/2023/8/79808_0s.png)
不用Global.asa也能实现统计在线人数吗?
2009-10-29 12:28:00
CSS 表格元素内容的定位 0
2008-08-01 17:31:00
Django处理Ajax发送的Get请求代码详解
2023-06-29 08:40:40
![](https://img.aspxhome.com/file/2023/7/78787_0s.png)
Python ini配置文件示例详解
2023-08-24 09:07:36
![](https://img.aspxhome.com/file/2023/1/62861_0s.png)
如何取得服务器上的用户组列表?
2010-01-18 20:54:00
Python详解复杂CSV文件处理方法
2021-04-05 11:12:02
![](https://img.aspxhome.com/file/2023/6/67936_0s.png)
怎样缩小SQL Server数据库的日志文件
2009-01-15 13:08:00
Oracle 11g安装错误提示未找到wfmlrsvcapp.ear的解决方法
2023-07-14 14:31:52
![](https://img.aspxhome.com/file/2023/6/64466_0s.jpg)
python更新列表的方法
2021-12-21 11:38:39
Golang算法问题之数组按指定规则排序的方法分析
2023-10-06 01:37:14
用 AjaxTags 简化 Ajax 开发
2007-11-27 00:00:00
详解使用Python处理文件目录的相关方法
2023-08-01 02:55:30
django之导入并执行自定义的函数模块图解
2023-07-27 02:45:19
![](https://img.aspxhome.com/file/2023/0/86240_0s.jpg)
python实现可将字符转换成大写的tcp服务器实例
2021-06-17 01:04:38
关于ASP中的类class
2007-08-19 15:37:00