Package: tcppinglib
TCPPINGLIBWhen it comes to measuring the connectivity and latency to web servers on the network level, an alternative method exists, which we call TCP Ping: a ping with special options that mimic the TCP handshake that takes place when an HTTP/HTTPS connection is established.TCPPingLibis a TCP oriented ping alternative written in pure Python. It is used to test the reachability of a service on a host using TCP/IP and measure the time it takes to connect to the specifed port.It is not only measuring connection overall time to the web server, but also measuring every steps between start point of a tcpping and connection which are dns lookup time, socket connection time, SSL socket connection time if possible and it also send basic HTTP GET request for the response and measure the response time.Features:love_you_gesture:No Dependency:TcpPingLib is a pure Python implementation of TCP Ping. It has no external dependency.:mechanical_leg:IPv6 Support:You can use TcpPingLib with the URLs with IPv6 address. You can also see the all resolved IP addresses for the specified address.:rocket:Fast:Developed for best and fastest performance with async functions likeasync_tcpping,async_multi_tcpping.:fire:Built-in Properties:Easily get the necessary information with the built-in models' properties about the TCP Ping which is sent.:eyes:Monitor:Determine whether the host is online or not wheneverpingis disabled or blocked, measure the latency.:hourglass:Certificate Expire:Check the days to certification expire date for the given URL if SSL connection can be established.:gem:Modern:This library uses the latest mechanisms offered by Python 3.6/3.7+ and is fully object-oriented.InstallationRecommended way to installtcppinglibis to usepip3$pip3installtcppinglibPython 3.7 or later is required to use the library.UsagetcppingSend TCP Ping to a URL.Import the function with the below code snippet.fromtcppinglibimporttcppingFunction Parameterstcpping(address,port:int=80,timeout:float=2,count:int=3,interval:float=3)addressThe hostname or FQDN of the host which tcp ping will be sent to.Type:strcountThe number of packets which will be sent toaddress.Type:intDefault:5portThe TCP port number that packets will be sent to.Type:intDefault:80(HTTP)timeoutThe maximum waiting time for receiving a reply in seconds.Type:floatDefault:2secondsintervalThe interval between sending each packet in secondsType:floatDefault:3secondsReturn ValueATcpHostobject will be returned containing with many usefull values about the TCP Ping.ip_address,port,packets_sent,packets_received,packet_loss,is_alive,min_rtt,avg_rtt,max_rttExample>>>fromtcppinglibimporttcpping>>>host=tcpping('www.google.com',interval=1.5)>>>host.is_alive# Check whether host is respondingTrue>>>host.ip_address# Resolved ip addresses of the given url['172.217.17.100']>>>host.min_rtt# Minimum round trip time for all process15.532>>>host.avg_rtt# Average round trip time for all process18.789>>>host.packet_loss# Percentage of packet loss0.0>>>host.port# Port number80multi_tcppingSend TCP Ping to multiple URL.Import the function with the below code snippet.fromtcppinglibimportmulti_tcppingFunction Parametersmulti_tcpping(addresses:list,port:int=80,timeout:float=2,count:int=5,interval:float=3,concurrent_tasks=50):addressThe hostname or FQDN of the host which tcp ping will be sent to.Type:strcountThe number of packets which will be sent toaddress.Type:intDefault:5portThe TCP port number that packets will be sent to.Type:intDefault:80(HTTP)timeoutThe maximum waiting time for receiving a reply in seconds.Type:floatDefault:2secondsintervalThe interval between sending each packet in secondsType:floatDefault:3secondsconcurrent_tasksThe maximum number of concurrent tasks to speed up processing. This value cannot exceed the maximum number of file descriptors configured on the operating system.Type:intDefault:50Return ValueATcpHostobject will be returned containing with many usefull values about the TCP Ping.ip_address,port,packets_sent,packets_received,packet_loss,is_alive,min_rtt,avg_rtt,max_rttExample>>>fromtcppinglibimportmulti_tcpping>>>hosts=multi_tcpping(['www.google.com','https://www.python.org','http://cnn.com'],interval=1.5,concurrent_tasks=20)>>>[host.is_aliveforhostinhosts]# Check whether hosts are responding respectively[True,True,True]>>>[host.avg_rttforhostinhosts]# Averate round trip times list for whole process.[88.602,279.328,131.029]>>>[host.ip_addressforhostinhosts]# Resolved ip addresses list[['172.217.169.100'],['151.101.12.223'],['151.101.193.67','151.101.65.67','151.101.1.67','151.101.129.67']]>>>[host.portforhostinhosts]# Port Number[80,80,80]async_tcppingSend TCP Ping to a URL.This function is non-blocking.Import the function with the below code snippet.fromtcppinglibimportasync_tcppingFunction Parametersasync_tcpping(address,port:int=80,timeout:float=2,count:int=5,interval:float=3)addressThe hostname or FQDN of the host which tcp ping will be sent to.Type:strcountThe number of packets which will be sent toaddress.Type:intDefault:5portThe TCP port number that packets will be sent to.Type:intDefault:80(HTTP)timeoutThe maximum waiting time for receiving a reply in seconds.Type:floatDefault:2secondsintervalThe interval between sending each packet in secondsType:floatDefault:3secondsReturn ValueATcpHostobject will be returned containing with many usefull values about the TCP Ping.ip_address,port,packets_sent,packets_received,packet_loss,is_alive,min_rtt,avg_rtt,max_rttExample>>>importasyncio>>>fromtcppinglibimportasync_tcpping>>>asyncdefhost_specs(address):...host=awaitasync_tcpping(address,count=7,interval=1.5)...returnhost.is_alive,host.avg_rtt,host.packet_loss...>>>asyncio.run(host_specs('https://www.google.com'))(True,450.629,0.0)async_multi_tcppingSend TCP Ping to multiple URL.This function is non-blocking.Import the function with the below code snippet.fromtcppinglibimportasync_multi_tcppingFunction Parametersasync_multi_tcpping(address,port:int=80,timeout:float=2,count:int=5,interval:float=3,concurrent_tasks=50)addressThe hostname or FQDN of the host which tcp ping will be sent to.Type:strcountThe number of packets which will be sent toaddress.Type:intDefault:5portThe TCP port number that packets will be sent to.Type:intDefault:80(HTTP)timeoutThe maximum waiting time for receiving a reply in seconds.Type:floatDefault:2secondsintervalThe interval between sending each packet in secondsType:floatDefault:3secondsconcurrent_tasksThe maximum number of concurrent tasks to speed up processing. This value cannot exceed the maximum number of file descriptors configured on the operating system.Type:intDefault:50Return ValueATcpHostobject will be returned containing with many usefull values about the TCP Ping.ip_address,port,packets_sent,packets_received,packet_loss,is_alive,min_rtt,avg_rtt,max_rttExamplefromtcppinglibimportasync_multi_tcppingimportasynciourls=[# FQDNs'https://www.google.com','https://www.trendyol.com','cnn.com',# IP Addresses'1.1.1.1']hosts=asyncio.run(async_multi_tcpping(urls,count=7,interval=1.5))forhostinhosts:print(host.is_alive,host.avg_rtt_all)# True 226.72# True 62.649# True 93.685# True 9.165ContributingComments and enhancements are welcome.All development is done onGitHub. UseIssuesto report problems and submit feature requests. Please include a minimal example that reproduces the bug.LicenseCopyright 2017-2022 Valentin BELYN.Code released under the GNU LGPLv3 license. See theLICENSEfor details.