Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c420dc3db | ||
|
|
54b52273da | ||
|
|
93fd6f916b | ||
|
|
8e2f4e3db8 | ||
|
|
bb77957ed4 | ||
|
|
a46c855960 | ||
|
|
0ea14fd132 | ||
|
|
7020adee58 | ||
|
|
399459c744 | ||
|
|
b4b01a5cf4 |
No files matched your search
@@ -1 +1,2 @@
|
||||
.*.sw*
|
||||
main
|
||||
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
//"./timer"
|
||||
"time"
|
||||
"fmt"
|
||||
"strings"
|
||||
"regexp"
|
||||
"io/ioutil"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
|
||||
var tcp_data string = read_tcp_file("/proc/net/tcp")
|
||||
|
||||
func main() {
|
||||
var loops int = 0
|
||||
// How to split on space-delimited fields, then colon-delimited fields?
|
||||
// How to turn this byte into a string?
|
||||
|
||||
// /proc/net/tcp hex addresses need to be reversed two-character-wise
|
||||
// and then converted byte by byte (2 char at a time)
|
||||
//fmt.Println(convert_address(reverse_string(reverse_bytes("0100007F"))))
|
||||
|
||||
for _ = range time.Tick(10 * time.Second) {
|
||||
fmt.Println("Waiting 10 seconds...")
|
||||
for num, row := range get_tcp_rows(tcp_data) {
|
||||
row_type := reflect.TypeOf(row)
|
||||
fmt.Println(num, " ", row_type)
|
||||
}
|
||||
// if loops modulo 6 (1min) then
|
||||
// for address in address_list do
|
||||
// if (grep address address_list | wc -l >=3) then
|
||||
// This is a port scan!
|
||||
// fi
|
||||
// done
|
||||
// elseif (wc -l old_tcp_file < wc -l tcp_file) then
|
||||
// for i in (wc -l tcp_file - wc -l old_tcp_flle) do
|
||||
// print New Connection! reverse_strng(reverse_bytes(tcp_file[i])) // This oversimplifies row value selection for the sake
|
||||
// // of pseudocode
|
||||
// done
|
||||
// else
|
||||
// "No new connections. Waiting another 10 seconds..."
|
||||
// fi
|
||||
loops++
|
||||
}
|
||||
}
|
||||
|
||||
func check(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Aiming for an array of [string]string maps
|
||||
// Am I looking for a map[string]interface here?
|
||||
func get_tcp_rows(connections_file string) []string {
|
||||
tcp_lines := strings.Split(connections_file, "\n")
|
||||
regexpression := regexp.MustCompile(`[\r\n\t\f\v]+`)
|
||||
tcp_columns := regexpression.Split(tcp_lines[0], -1)
|
||||
var tcp_values map[string]string
|
||||
|
||||
for i, line := range tcp_lines[1:] {
|
||||
trim_line := strings.TrimSpace(line)
|
||||
values := regexpression.Split(trim_line, -1)
|
||||
column := tcp_columns[i]
|
||||
tcp_values[column] = values
|
||||
}
|
||||
return tcp_values
|
||||
}
|
||||
|
||||
// Take a string, create a rune slice, and use a loop to reverse it character-wise.
|
||||
func reverse_bytes(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := len(runes)-2, len(runes)-1; j > 0; i, j = i-2, j-2 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
||||
func reverse_string(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
// Store data function
|
||||
// Loads all fields and subfields into storage (memory? where?)
|
||||
// State check function
|
||||
// hash each line, use to determine new lines, convert to readable, and print
|
||||
|
||||
|
||||
func convert_address(address string) []byte {
|
||||
output, err := hex.DecodeString(address)
|
||||
check(err)
|
||||
return output
|
||||
}
|
||||
func read_tcp_file(connections_file_path string) string {
|
||||
data, err := ioutil.ReadFile(connections_file_path)
|
||||
check(err)
|
||||
fmt.Println("Data file read successfully.\n")
|
||||
return string(data)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
//"reflect"
|
||||
)
|
||||
|
||||
func New(duration_int int, unit string) *time.Timer {
|
||||
|
||||
start := time.NewTimer(0)
|
||||
duration := time.Duration(duration_int)
|
||||
// fmt.Println(reflect.TypeOf(duration))
|
||||
// timer_10s := time.NewTimer(10 * time.Second)
|
||||
// timer_1m := time.NewTimer(1 * time.Minute)
|
||||
fmt.Println("Duration: ", duration_int, "Unit: ", unit, ".")
|
||||
if unit == "Second" {
|
||||
start = time.NewTimer(duration * time.Second)
|
||||
} else if unit == "Minute" {
|
||||
start = time.NewTimer(duration * time.Minute)
|
||||
} else {
|
||||
fmt.Println("Unit not recognized.")
|
||||
}
|
||||
fmt.Println("Waiting ", duration_int, " ", unit, ".")
|
||||
if start.Stop() {
|
||||
<-start.C
|
||||
fmt.Println("Done waiting ", duration_int, " ", unit, "!")
|
||||
}
|
||||
return start
|
||||
// for elapsed < ten_seconds {
|
||||
//}
|
||||
// for
|
||||
}
|
||||
|
||||
func Reset
|
||||
Reference in new issue
Block a user