本文整理汇总了Python中pyroute2.IPRoute.connect方法的典型用法代码示例。如果您正苦于以下问题:Python IPRoute.connect方法的具体用法?Python IPRoute.connect怎么用?Python IPRoute.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyroute2.IPRoute
的用法示例。
在下文中一共展示了IPRoute.connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestProxyData
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import connect [as 别名]
class TestProxyData(TestData):
def setup(self):
create_link('dummyX', 'dummy')
t_url = 'unix://\0%s' % (uuid.uuid4())
p_url = 'unix://\0%s' % (uuid.uuid4())
self.connect = Event()
self.release = Event()
target = Process(target=_run_remote_uplink,
args=(t_url, self.connect, self.release))
target.daemon = True
target.start()
self.connect.wait()
self.connect.clear()
proxy = Process(target=_run_remote_uplink,
args=(p_url, self.connect, self.release))
proxy.daemon = True
proxy.start()
self.connect.wait()
self.connect.clear()
self.ip = IPRoute(do_connect=False)
link, proxy = self.ip.connect(p_url)
self.ip.register('bala', proxy)
link, host = self.ip.connect(t_url, addr=proxy)
service = self.ip.discover(self.ip.default_target, addr=host)
self.ip.default_peer = host
self.ip.default_dport = service
self.dev = self.ip.link_lookup(ifname='dummyX')
示例2: _test_noautoconnect
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import connect [as 别名]
def _test_noautoconnect(self):
ip = IPRoute(do_connect=False)
_assert_uplinks(ip, 0)
addr = ip.connect()
_assert_uplinks(ip, 1)
ip.disconnect(addr)
_assert_uplinks(ip, 0)
ip.release()
示例3: len
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import connect [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 connect [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