Created
November 27, 2009 07:35
-
-
Save kshimo69/243876 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: fileencoding=utf8 | |
import socket | |
import random | |
IPMSG_VERSION = 0x0001 | |
IPMSG_SENDMSG = 0x00000020 | |
LOCAL_USER = u"自動通知".encode('shift-jis') | |
LOCAL_HOST = "0.0.0.0" | |
PORT = 2425 | |
USERS = { | |
'username':'ipaddr', | |
} | |
def usage(name): | |
print "usage: %s <user name> <message>" % name | |
def makemsg(message): | |
return "1:%d:%s:%s:%d:%s" % ( | |
random.randint(1, 1000), | |
LOCAL_USER, | |
LOCAL_HOST, | |
IPMSG_SENDMSG, | |
unicode(message, 'utf-8', 'ignore').encode('shift-jis')) | |
def sendmsg(user, message): | |
try: | |
soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) | |
host = socket.gethostbyname(USERS[user]) | |
soc.sendto(makemsg(message), 0, (host, PORT)) | |
except socket.error, detail: | |
print 'ERR : %s' % detail | |
exit(1) | |
print "sended to %s: %s" % (user, message) | |
if __name__ == "__main__": | |
import sys | |
if len(sys.argv) < 3: | |
usage(sys.argv[0]) | |
exit(1) | |
else: | |
sendmsg(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment