跳转到主要内容

未提供项目描述

项目描述

ixconfig

快速简单的ifconfigiwconfig解析。

安装

pip install ixconfig

使用

import ixconfig

# ifconfig

# returns an Ifc object - runs `ifconfig`
ifc = ixconfig.Ifc()
# which behaves like a dict
assert ifc['wlan0']['ip'] == "192.168.1.237"
# or an attrdict
assert ifc.wlan0.ip == "192.168.1.237"

# when you pass in an interface, it runs `ifconfig wlan0`
ifc = ixconfig.Ifc('wlan0')
# and then you can just access the attributes directly
assert ifc['ip'] == "192.168.1.237"
assert ifc.ip == "192.168.1.237"

# iwconfig

iwc = ixconfig.Iwc()
assert iwc['wlan0']['quality'] == 92.0
assert iwc.wlan0.quality == 92.0

iwc = ixconfig.Iwc('wlan0')
assert iwc['quality'] == 92.0
assert iwc.quality == 92.0

注意

这是我从另一个项目提取出来的代码。最终,我认为这个功能应该由ifcfg来覆盖,但目前它们还没有处理iwconfig

所以直到那时,这个包涵盖了ifconfig和iwconfig的非常基础的解析。

示例输出

ifc = ixconfig.Ifc()
iwc = ixconfig.Iwc()
print(ifc)
print(iwc)
( $ ifconfig ) {
    "docker0": {
        "broadcast": "172.17.255.255",
        "ip": "172.17.0.1",
        "ipv6": "fe80::42:f2ff:fe23:bb38",
        "mac": "02:42:f2:23:bb:38",
        "mtu": 1500,
        "name": "docker0",
        "netmask": "255.255.0.0",
        "rx_dropped": 0,
        "rx_errors": 0,
        "rx_overruns": 0,
        "rx_packets": 21326,
        "tx_carrier": 0,
        "tx_collisions": 0,
        "tx_dropped": 0,
        "tx_errors": 0,
        "tx_overruns": 0,
        "tx_packets": 30842
    },
    ...
    "wlan0": {
        "broadcast": "192.168.1.255",
        "ip": "192.168.1.237",
        "ipv6": "fe80::2998:5b3c:8ffb:a03d",
        "mac": "dc:a6:32:5d:df:ce",
        "mtu": 1500,
        "name": "wlan0",
        "netmask": "255.255.255.0",
        "rx_dropped": 0,
        "rx_errors": 0,
        "rx_overruns": 0,
        "rx_packets": 1960938,
        "tx_carrier": 0,
        "tx_collisions": 0,
        "tx_dropped": 0,
        "tx_errors": 0,
        "tx_overruns": 0,
        "tx_packets": 2790429
    }
}

( $ iwconfig ) {
    "wlan0": {
        "access_point": "A0:8E:78:59:45:D2",
        "bitrate": 72.2,
        "bitrate_unit": "Mb/s",
        "freq": 2.462,
        "freq_unit": "GHz",
        "mode": "Managed",
        "name": "wlan0",
        "power_mgmt": "on",
        "quality": 50.0,
        "quality_ratio": 0.7142857142857143,
        "ssid": "MySpectrumWiFicc-2G",
        "strength": -60.0,
        "strength_unit": "dBm"
    }
}

项目详情


下载文件

下载适用于您平台文件。如果您不确定要选择哪个,了解更多关于安装包的信息。

源分发

ixconfig-0.1.1.tar.gz (5.1 kB 查看哈希)

上传时间:

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面