本文整理汇总了Python中pyroute2.IPRoute.get方法的典型用法代码示例。如果您正苦于以下问题:Python IPRoute.get方法的具体用法?Python IPRoute.get怎么用?Python IPRoute.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyroute2.IPRoute
的用法示例。
在下文中一共展示了IPRoute.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mroute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import get [as 别名]
def mroute():
ip = IPRoute() # family = NETLINK_ROUTE "Receives routing and link
# updates and may be used to modify the routing tables"
ip.monitor()
while True:
for raw in ip.get():
print '{event:10} {attrs}'.format(**raw)
示例2: main_loop
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import get [as 别名]
class main_loop():
def __init__(self,group=RTMGRP_LINK |RTMGRP_IPV4_IFADDR,family= NETLINK_ROUTE,log=False):
IPRoute.groups = RTMGRP_LINK |RTMGRP_IPV4_IFADDR
IPRoute.groups = RTMGRP_LINK
IPRoute.family = family
self.ip = IPRoute()
self.counter = 0
self.log = log
def monitor(self):
self.ip.monitor()
while True :
self.buf = self.ip.get()
self.parse_buf(self.buf[0])
print self.buf
示例3: len
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import get [as 别名]
#!/usr/bin/python
'''
Slightly more complicate example, than trace_ip_link.
'''
import sys
from pyroute2 import IPRoute
from Queue import Empty
if len(sys.argv) < 2:
print('choose program to run, e.g.:')
print('%s ip link show' % (sys.argv[0]))
sys.exit(0)
ip = IPRoute(debug=True)
q = ip.connect('ptrace://%s' % ' '.join(sys.argv[1:]), no_stdout=True)
while True:
try:
for msg in ip.get(q, raw=True):
print(msg)
except Empty:
break
示例4: IPRoute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import get [as 别名]
#!/usr/bin/python
'''
Launch external command 'ip link show' and analyze
netlink traffic, that it sends/receives. Just like
tcpdump, but for netlink protocol.
'''
import sys
from pyroute2 import IPRoute
from Queue import Empty
from pprint import pprint
ip = IPRoute()
q = ip.connect('ptrace://' + ' '.join(sys.argv[1:]))
while True:
try:
pprint(ip.get(q, raw=True))
except Empty:
break