根据要求,这是python服务器......
#!/usr/bin/python
import os
import socket
print " Loading Bindings..."
settings = {}
line = 0
for each in open('/path/to/actions.txt', 'r'):
line = line + 1
each = each.rstrip()
if each <> "":
if each[0] <> '#':
a = each.partition(':')
if a[2]:
settings[a[0]] = a[2]
else:
print " Err @ line",line,":",each
print " Starting Server...",
port = 12345
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", port))
print "OK."
print " Listening on port:", port
while True:
datagram = s.recv(1024)
if not datagram:
break
print "Rx Cmd:", datagram
if settings.has_key(datagram):
print "Launch:", settings[datagram]
os.system(settings[datagram]+" &")
s.close()
配置文件“actions.txt”使用格式“action-name:corresponding-shell-command”,即
# Hash denotes a comment
webroot:nautilus /var/www
ftp:filezilla
edit_homepage:gedit /var/www/homepage/htdocs/index.php
此代码不会检查传入 UDP 数据包的原始 IP,因为我在 localhost 上运行它,我受到其他任何人的防火墙保护,并且无论如何检查都不会提供针对欺骗的保护。
我没有时间重写它以使用 TCP/IP,但 Python 是一种值得了解的语言,所以如果你真的想要那个功能,我会留给你一个 google 来搜索“Python”和“SOCK_STREAM” . 不过,这可能不值得您费心,配置防火墙更容易,这样就不会受到欺骗的本地主机数据包可以通过并修改代码以确保它只侦听来自环回的数据包。