cup.net package¶
- description:
network related module
- cup.net.get_hostip(hostname=None)[source]¶
get ipaddr of a host
- Parameters:
hostname – None, by default, will use udp to get ipaddr for ipv4 if not None, will use hostname to convert to ipaddr
- cup.net.getip_byinterface(iface='eth0')[source]¶
get ipaddr of a network adapter
- Platform:
Linux/Unix
E.g.
import cup print(cup.net.getip_byinterface('eth0')) print(cup.net.getip_byinterface('eth1')) print(cup.net.getip_byinterface('xgbe0'))
- cup.net.port_listened(host, port, is_ipv6=False)[source]¶
check if the port is being listened on the host
- cup.net.set_sock_keepalive_linux(sock, after_idle_sec=1, interval_sec=3, max_fails=5)[source]¶
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:
sock – socket
after_idle_sec – for TCP_KEEPIDLE. May not work, depends on ur system
interval_sec – for TCP_KEEPINTVL
max_fails – for TCP_KEEPCNT
- cup.net.set_sock_linger(sock, l_onoff=1, l_linger=0)[source]¶
set socket linger param (socket.SO_LINGER)
I.g.
sock.setsockopt( socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 0, 0) )
- cup.net.set_sock_quickack(sock)[source]¶
open quickack for the socket
I.g.
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_QUICKACK, 1)
Subpackages¶
- cup.net.asyn package
- Submodules
- cup.net.asyn.common module
- cup.net.asyn.conn module
CConnectionManager
CConnectionManager.NET_RW_SIZE
CConnectionManager.QueueError
CConnectionManager.SOCK_ALIVE_PARAMS
CConnectionManager.add_write_job()
CConnectionManager.bind()
CConnectionManager.cleanup_error_context()
CConnectionManager.close_socket()
CConnectionManager.connect()
CConnectionManager.do_check_msg_ack_loop()
CConnectionManager.dump_stats()
CConnectionManager.get_needack_dict()
CConnectionManager.get_recv_msg()
CConnectionManager.get_recv_msg_ind()
CConnectionManager.get_recv_queue()
CConnectionManager.global_sock_keepalive()
CConnectionManager.listen_new_connect()
CConnectionManager.poll()
CConnectionManager.push_msg2needack_queue()
CConnectionManager.push_msg2sendqueue()
CConnectionManager.read()
CConnectionManager.stop()
- cup.net.asyn.context module
CConnContext
CConnContext.CONTEXT_QUEUE_SIZE
CConnContext.do_recv_data()
CConnContext.get_context_info()
CConnContext.get_listened_peer()
CConnContext.get_peerinfo()
CConnContext.get_sending_queue()
CConnContext.get_sock()
CConnContext.is_detroying()
CConnContext.is_reading()
CConnContext.move2recving_msg()
CConnContext.put_msg()
CConnContext.release_readlock()
CConnContext.release_writelock()
CConnContext.set_conn_man()
CConnContext.set_destoryed()
CConnContext.set_listened_peer()
CConnContext.set_peerinfo()
CConnContext.set_reading()
CConnContext.set_sock()
CConnContext.to_destroy()
CConnContext.try_move2next_sending_msg()
CConnContext.try_readlock()
CConnContext.try_writelock()
- cup.net.asyn.ioloop module
- cup.net.asyn.msg module
CAckMsg
CNetMsg
CNetMsg.MSGTYPE
CNetMsg.MSG_FLAG_MAN
CNetMsg.MSG_SIGN
CNetMsg.add_flag()
CNetMsg.add_retry_times()
CNetMsg.get_body()
CNetMsg.get_bodylen()
CNetMsg.get_callback_function()
CNetMsg.get_errmsg()
CNetMsg.get_flag()
CNetMsg.get_from_addr()
CNetMsg.get_last_retry_time()
CNetMsg.get_msg_context()
CNetMsg.get_msg_len()
CNetMsg.get_msg_type()
CNetMsg.get_order_counts()
CNetMsg.get_resend_flag()
CNetMsg.get_retry_interval()
CNetMsg.get_retry_times()
CNetMsg.get_to_addr()
CNetMsg.get_total_timeout()
CNetMsg.get_uniq_id()
CNetMsg.get_write_bytes()
CNetMsg.is_a_recvmsg()
CNetMsg.is_a_sendmsg()
CNetMsg.is_msg_already_sent()
CNetMsg.is_recvmsg_complete()
CNetMsg.is_sendmsg_complete()
CNetMsg.is_valid4send()
CNetMsg.pre_resend()
CNetMsg.push_data()
CNetMsg.seek_write()
CNetMsg.set_body()
CNetMsg.set_callback_function()
CNetMsg.set_errmsg()
CNetMsg.set_flag()
CNetMsg.set_from_addr()
CNetMsg.set_last_retry_time()
CNetMsg.set_msg_context()
CNetMsg.set_msg_type()
CNetMsg.set_need_head()
CNetMsg.set_resend_flag()
CNetMsg.set_retry_interval()
CNetMsg.set_retry_times()
CNetMsg.set_to_addr()
CNetMsg.set_total_timeout()
CNetMsg.set_uniq_id()
netmsg_tostring()
- cup.net.asyn.msgcenter module
IMessageCenter
IMessageCenter.close_socket()
IMessageCenter.default_handle()
IMessageCenter.dump_stat()
IMessageCenter.global_sock_keepalive()
IMessageCenter.handle()
IMessageCenter.is_stopping()
IMessageCenter.post_msg()
IMessageCenter.pre_handle()
IMessageCenter.run()
IMessageCenter.setup()
IMessageCenter.stop()
Submodules¶
cup.net.ipaddr module¶
- description:
host route info related module
cup.net.route module¶
- description:
host route info related module
- class cup.net.route.RouteInfo[source]¶
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" } ]
- ROUTE_FILE = '/proc/net/route'¶
- get_interface_by_ip(ip)[source]¶
get the interface which can reach to the ip
- Parameters:
ip – destination ip
- Returns:
interface name which can reach to the ip. None if failed.