Skip to content

Instantly share code, notes, and snippets.

@kshimo69
Created March 13, 2012 10:20
Show Gist options
  • Save kshimo69/2028009 to your computer and use it in GitHub Desktop.
Save kshimo69/2028009 to your computer and use it in GitHub Desktop.
ipmsgを送るやつ
#!/usr/bin/python
# vim: fileencoding=utf8
import socket
import random
IPMSG_VERSION = 0x0001
IPMSG_SENDMSG = 0x00000020
IPMSG_SECRETOPT = 0x00000200
IPMSG_HOGEHOGE = 0x00000220
LOCAL_USER = u"アラーム案件通知".encode('shift-jis')
LOCAL_HOST = "127.0.0.1"
PORT = 2425
USERS = {
'shimomura':'xxx.xxx.xxx.xxx',
}
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_HOGEHOGE,
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:\n%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