Compare commits
No commits in common. "54b52273da9bf61d17f3f4569ccf06d8f9ad25b9" and "a46c85596049e3920d7f1f61052c75fd3f3ae3d3" have entirely different histories.
54b52273da
...
a46c855960
49
main.go
49
main.go
@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"./timer"
|
||||||
//"./timer"
|
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -12,10 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var tcp_data string = read_tcp_file("/proc/net/tcp")
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var loops int = 0
|
|
||||||
// How to split on space-delimited fields, then colon-delimited fields?
|
// How to split on space-delimited fields, then colon-delimited fields?
|
||||||
// How to turn this byte into a string?
|
// How to turn this byte into a string?
|
||||||
|
|
||||||
@ -23,28 +18,8 @@ func main() {
|
|||||||
// and then converted byte by byte (2 char at a time)
|
// and then converted byte by byte (2 char at a time)
|
||||||
//fmt.Println(convert_address(reverse_string(reverse_bytes("0100007F"))))
|
//fmt.Println(convert_address(reverse_string(reverse_bytes("0100007F"))))
|
||||||
|
|
||||||
for _ = range time.Tick(10 * time.Second) {
|
timer.New()
|
||||||
fmt.Println("Waiting 10 seconds...")
|
tcp_rows(read_tcp_file("/proc/net/tcp"))
|
||||||
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) {
|
func check(e error) {
|
||||||
@ -53,21 +28,17 @@ func check(e error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aiming for an array of [string]string maps
|
func tcp_rows(connections_file string) {
|
||||||
// Am I looking for a map[string]interface here?
|
regexpression := regexp.MustCompile(`[^a-zA-Z0-9:\r\n\t\v]+`)
|
||||||
func get_tcp_rows(connections_file string) []string {
|
|
||||||
tcp_lines := strings.Split(connections_file, "\n")
|
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:] {
|
for _, line := range tcp_lines {
|
||||||
trim_line := strings.TrimSpace(line)
|
trim_line := strings.TrimSpace(line)
|
||||||
values := regexpression.Split(trim_line, -1)
|
values := regexpression.ReplaceAllString(trim_line, ",")
|
||||||
column := tcp_columns[i]
|
// Debug
|
||||||
tcp_values[column] = values
|
// fmt.Println("New Line ==========")
|
||||||
|
fmt.Println(values)
|
||||||
}
|
}
|
||||||
return tcp_values
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a string, create a rune slice, and use a loop to reverse it character-wise.
|
// Take a string, create a rune slice, and use a loop to reverse it character-wise.
|
||||||
|
|||||||
@ -6,30 +6,16 @@ import (
|
|||||||
//"reflect"
|
//"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(duration_int int, unit string) *time.Timer {
|
func New() {
|
||||||
|
|
||||||
start := time.NewTimer(0)
|
timer_10s := time.NewTimer(10 * time.Second)
|
||||||
duration := time.Duration(duration_int)
|
|
||||||
// fmt.Println(reflect.TypeOf(duration))
|
|
||||||
// timer_10s := time.NewTimer(10 * time.Second)
|
|
||||||
// timer_1m := time.NewTimer(1 * time.Minute)
|
// timer_1m := time.NewTimer(1 * time.Minute)
|
||||||
fmt.Println("Duration: ", duration_int, "Unit: ", unit, ".")
|
fmt.Println("Waiting 10 seconds...")
|
||||||
if unit == "Second" {
|
<-timer_10s.C
|
||||||
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 elapsed < ten_seconds {
|
||||||
//}
|
//}
|
||||||
// for
|
// for
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reset
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user