mdw-test/: Include some random utilities I've found handy for testing.
[secnet] / mdw-test / mkping
diff --git a/mdw-test/mkping b/mdw-test/mkping
new file mode 100755 (executable)
index 0000000..d22c93d
--- /dev/null
@@ -0,0 +1,24 @@
+#! /usr/bin/python
+
+import os as OS
+from sys import stdout, argv
+import impacket.ImpactPacket as I
+
+sndname, sndaddr, rcpname, rcpaddr, outfile = argv[1:]
+
+ip = I.IP()
+ip.set_ip_src(sndaddr);
+ip.set_ip_dst(rcpaddr);
+icmp = I.ICMP()
+icmp.set_icmp_type(icmp.ICMP_ECHO)
+icmp.set_icmp_cksum(0)
+icmp.auto_checksum = 1
+icmp.contains(I.Data('Hello, %s, from %s!' % (rcpname, sndname)))
+ip.contains(icmp)
+
+if outfile == '-':
+  stdout.write(ip.get_packet())
+else:
+  outtmp = outfile + '.new'
+  with open(outtmp, 'wb') as f: f.write(ip.get_packet())
+  OS.rename(outtmp, outfile)