network daemon testing#
Is the server online?#
To test whether a server is accepting connections, you can combine the -v and -z flags together:
pync -vz host.example.com 80
py -m pync -vz host.example.com 80
import pync
pync.run('-vz host.example.com 80')
The -z flag tells pync to close the connection immediately (zero input/output) while the -v flag prints a connection success or failure message to the console:
...
Connection to host.example.com 80 port [tcp/http] succeeded!
...
pync: connect to host.example.com port 80 (tcp) failed: Connection refused
You can also scan multiple ports on a machine by passing a range of port numbers. See Port Scanning for more.
Is the server responding?#
It can also be useful to interact with a server to test how it responds to certain requests.
For example, a web server should respond to a HTTP GET request by sending back a HTTP status code and the contents of the requested web page (if it exists).
Connect to a web server:
pync host.example.com 80
py -m pync host.example.com 80
import pync
pync.run('host.example.com 80')
Once connected, send a GET request for the home page by typing the following and hitting enter a couple of times:
GET / HTTP/1.1
If all goes well, the server should respond with a HTTP 200 OK status along with any HTTP headers and the contents of the requested web page (index.html in this case):
HTTP/1.1 200 OK
Server: host.example.com
Content-Type: text/html; charset=UTF-8
...
<!doctype html>
<html>
<body>
<h1>Example Web Page!</h1>
</body>
</html>