From bec68afccfdd48a031ba064bf7f76cfc899fd5ac Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Tue, 27 Aug 2013 18:35:11 +0000 Subject: Add wol-valiant script git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@643 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- wol-valiant | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 wol-valiant diff --git a/wol-valiant b/wol-valiant new file mode 100755 index 0000000..61ee229 --- /dev/null +++ b/wol-valiant @@ -0,0 +1,66 @@ +#!/usr/bin/python + +# ferm rule: +# daddr 172.22.118.10 +# proto tcp dport 22 tcp-flags (SYN ACK FIN RST) SYN +# mod state state NEW +# mod limit limit 1/minute limit-burst 1 +# NFLOG nflog-group 1371 nflog-prefix "ssh to valiant"; + +import dpkt, nflog, socket, subprocess, sys, time +import optparse + +NFLOG_GROUP = 1371 + +def cb(payload): + #print payload + #print payload.__dict__ + + #print "payload len ", payload.get_length() + data = payload.get_data() + pkt = dpkt.ip.IP(data) + #print "proto:", pkt.p + #print "source: %s" % socket.inet_ntoa(pkt.src) + #print "dest: %s" % socket.inet_ntoa(pkt.dst) + #if pkt.p == dpkt.ip.IP_PROTO_TCP: + # print " sport: %s" % pkt.tcp.sport + # print " dport: %s" % pkt.tcp.dport + + #return 1 + print "[%s] python callback called because of %s!"%(time.strftime("%Y-%m-%d %H:%M:%S"), socket.inet_ntoa(pkt.src)) + subprocess.call(['wakeonlan', MAC]) + subprocess.call(['ip', 'neigh', 'replace', IPADDR, 'lladdr', MAC, 'nud', 'stale', 'dev', INTERFACE]) + sys.stdout.flush() + +parser = optparse.OptionParser() +parser.set_usage("%prog ") +(options, args) = parser.parse_args() + +if len(args) != 3: + parser.print_help() + sys.exit(1) +MAC = args[0] +IPADDR = args[1] +INTERFACE = args[2] + + +l = nflog.log() + +print "setting callback" +l.set_callback(cb) + +print "open" +l.fast_open(NFLOG_GROUP, socket.AF_INET) + +print "trying to run" +try: + l.try_run() +except KeyboardInterrupt, e: + print "interrupted" + + +print "unbind" +l.unbind(socket.AF_INET) + +print "close" +l.close() -- cgit v1.2.3