UDP Client

From PyMOTW :

import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('', 8080)
message = 'This is the message.  It will be repeated.'


    # Send data
    print >>sys.stderr, 'sending "%s"' % message
    sent = sock.sendto(message, server_address)

    # Receive response
    print >>sys.stderr, 'waiting to receive'
    data, server = sock.recvfrom(4096)
    print >>sys.stderr, 'received "%s"' % data

    print >>sys.stderr, 'closing socket'

UDP Server

From PyMOTW :

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind the socket to the port
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
while True:
    print >>sys.stderr, '\nwaiting to receive message'
    data, address = sock.recvfrom(4096)

    print >>sys.stderr, 'received %s bytes from %s' % (len(data), address)
    print >>sys.stderr, data

    if data:
        sent = sock.sendto(data, address)
        print >>sys.stderr, 'sent %s bytes back to %s' % (sent, address)

Curl tips

curl -I -X DELETE  http://localhost/blah
curl --header "X-MyHeader: 123"
curl -X POST --header "Content-Type: application/json" -d '{"test": true}' http://localhost/blah

If more than 10 telnet sessions to a server fail

per_source = 10 in /etc/xinetd.d/telnet or /etc/xinetd.conf

Start xinetd with debugs turned on

/usr/sbin/xinetd -f /etc/xinetd.conf -d

Check duplicate ip with arping

bash-4.2 ~$ arping -D -c 3 -I ens32
ARPING from ens32
Unicast reply from [18:E7:28:2E:92:9C]  1.747ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
bash-4.2 ~$ echo $?
bash-4.2 ~$

Test tcp connections with nc


nc -vz targetServer portNum

For example:

bash-3.2 ~$ nc -vz erdos 22
Connection to erdos 22 port [tcp/ssh] succeeded!
bash-3.2 ~$

Force NTP sync

sudo systemctl stop ntpd
sudo ntpdate -s
sudo systemctl start ntpd