Skip to content

Instantly share code, notes, and snippets.

@froop
Last active August 11, 2022 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froop/045a77b81f2c6d07c80147ef8bbdb6da to your computer and use it in GitHub Desktop.
Save froop/045a77b81f2c6d07c80147ef8bbdb6da to your computer and use it in GitHub Desktop.
[Python] syslog minimum client
#!/usr/bin/env python3
import socket
import datetime
now = datetime.datetime.now().strftime('%b %d %H:%M:%S')
msg = '<34>%s testhost TestTCP: aaa111' % now
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 514))
sock.sendall(msg.encode('utf-8'))
sock.close()
#!/usr/bin/env python3
import socket
import datetime
now = datetime.datetime.now().strftime('%b %d %H:%M:%S')
msg = '<34>%s testhost TestUDP: aaa111' % now
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg.encode('utf-8'), ('127.0.0.1', 514))
sock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment