| author: | YangGuang yangguang07@baidu.com |
|---|---|
| create_date: | 2014 |
| last_date: | 2014 |
| descrition: | host route info related module |
Bases: object
Handler of Route Info for Linux system, for ipv4 only.
E.g.
from cup.net import route
ri = route.RouteInfo()
print json.dumps(ri.get_route_by_ip('10.32.19.92'), indent=1)
print json.dumps(ri.get_routes(), indent=1)
Return
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "10.0.0.0",
"Mask": "255.0.0.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "10.226.71.1",
"Flags": "0003",
"IRTT": "0"
}
[
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "10.226.71.0",
"Mask": "255.255.255.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "0.0.0.0",
"Flags": "0001",
"IRTT": "0"
},
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "169.254.0.0",
"Mask": "255.255.0.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "0.0.0.0",
"Flags": "0001",
"IRTT": "0"
},
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "192.168.0.0",
"Mask": "255.255.0.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "10.226.71.1",
"Flags": "0003",
"IRTT": "0"
},
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "172.16.0.0",
"Mask": "255.240.0.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "10.226.71.1",
"Flags": "0003",
"IRTT": "0"
},
{
"Use": "0",
"Iface": "eth1",
"Metric": "0",
"Destination": "10.0.0.0",
"Mask": "255.0.0.0",
"RefCnt": "0",
"MTU": "0",
"Window": "0",
"Gateway": "10.226.71.1",
"Flags": "0003",
"IRTT": "0"
}
]
get the interface which can reach to the ip :param ip:
destination ip
| Returns: | interface name which can reach to the ip. None if failed. |
|---|
| author: | Guannan Ma |
|---|---|
| create_date: | 2014 |
| last_date: | 2014 |
| descrition: | network related module |
拿到某hostname的ip地址.
| Parameters: | hostname – 机器的hostname, 默认为None代表不传值, 函数将自动获取当前机器的ip |
|---|
获得某个网卡的ip地址 E.g.
import cup
print cup.net.getip_byinterface('eth0')
print cup.net.getip_byinterface('eth1')
print cup.net.getip_byinterface('xgbe0') # 万兆网卡
Set TCP keepalive on an open socket. It activates after 1 second (after_idle_sec) of idleness, then sends a keepalive ping once every 3 seconds (interval_sec), and closes the connection after 5 failed ping (max_fails), or 15 seconds
| Parameters: |
|
|---|