--- /dev/null
+// Copyright (C) Jann Horn (2013)
+// You can redistribute this code under the terms of the GPLv2 or GPLv3.
+// THIS PROGRAM IS FOR EDUCATIONAL PURPOSES ONLY!
+// I AM NOT RESPONSIBLE FOR WHAT YOU DO WITH THIS PROGRAM OR THE IMPACT THIS
+// PROGRAM MIGHT HAVE ON YOUR SYSTEMS! YOU HAVE BEEN WARNED!
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+char *target;
+
+void run(void) {
+ int pipefds[2];
+ if (pipe(pipefds)) perror("can't create pipe"), exit(1);
+ int parent_fd = pipefds[0];
+ int child_fd = pipefds[1];
+
+ pid_t pid = fork();
+ if (pid < 0) perror("can't fork"), exit(1);
+
+ if (pid == 0) {
+ int nullfd = open("/dev/null", O_RDWR);
+ dup2(nullfd, 0);
+ dup2(nullfd, 2);
+ close(nullfd);
+ close(parent_fd);
+ dup2(child_fd, 1);
+ close(child_fd);
+ execlp("hping3", "hping3", "-c", "20", "-p", "80", "-i", "u100000", "--syn", target, NULL);
+ perror("can't exec"), exit(1);
+ }
+ close(child_fd);
+
+ char indata[4096];
+ int indata_written = 0;
+ int rres;
+ while ((rres=read(parent_fd, indata+indata_written, 4095-indata_written)) > 0) {
+ indata_written += rres;
+ if (indata_written >= 4095) fputs("too much information", stderr), exit(1);
+ }
+ if (rres < 0) perror("failure reading from child"), exit(1);
+ indata[indata_written] = '\0';
+ close(parent_fd);
+
+ char *s = indata;
+ int last_id = -1;
+ int sum = 0;
+ while ((s=strstr(s, " id=")) != NULL) {
+ s += 4;
+ int id = atoi(s);
+ if (last_id != -1) {
+ int diff = id - last_id;
+ if (diff < 0) diff += (256*256);
+ sum += diff;
+ }
+ last_id = id;
+ }
+
+ printf("%i %i\n", (int)time(NULL), sum);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2) fputs("bad invocation\n", stderr), exit(1);
+ target = argv[1];
+
+ while (1) {
+ run();
+ sleep(300);
+ }
+}