Python的pyroute2网络模块

  • 时间:
  • 浏览:1
  • 来源:大发PK10APP下载_大发PK10APP官方

        print(message)

IPRoute-tc:https://www.mankier.com/8/tc

         address='10.0.0.1', mask=24,

         broadcast='10.0.0.255')

# bring it down

    # With IPRoute objects you have to call bind() manually

         broadcast='10.0.0.255')

源码库:https://github.com/svinota/pyroute2

ipr.addr('add', index=dev,

官方文档:http://docs.pyroute2.org/iproute.html

from pyroute2 import IPRoute

Pyroute2是纯python的netlink库,只都要python标准库不都要许多第三方的库。

         address='10.0.0.2', mask=24,

with DQuotSocket() as ds:

from pyroute2 import IPRoute

# bring it up

最常用的是监控事件,这类于监控磁盘空间事件:

        print(message)

# add primary IP address

# change the interface MAC address and rename it just for fun

# create an interface

# add secondary IP address

ipr.addr('add', index=dev,

    for message in ds.get():

dev = ipr.link_lookup(ifname='brx')[0]

    for message in ipr.get():

         address='00:11:22:33:44:55',

    ipr.bind()

ipr.link('add', ifname='brx', kind='bridge')

ipr = IPRoute()

ipr.link('set', index=dev, state='down')

ipr.link('set', index=dev, state='up')

with IPRoute() as ipr:

         ifname='br-ctrl')

# lookup the index

from pyroute2 import DQuotSocket

ipr.link('set', index=dev,

已经监控IP路由