Pārlūkot izejas kodu

playing around with the terminal interface

AETH-erial 10 mēneši atpakaļ
vecāks
revīzija
bb85081958
3 mainītis faili ar 38 papildinājumiem un 31 dzēšanām
  1. 16 4
      cmd/kyoketsu-web/kyoketsu-web.go
  2. 2 1
      cmd/kyoketsu/kyoketsu.go
  3. 20 26
      pkg/local.go

+ 16 - 4
cmd/kyoketsu-web/kyoketsu-web.go

@@ -29,9 +29,11 @@ package main
 
 import (
 	"database/sql"
+	"flag"
 	"fmt"
 	"log"
 	"os"
+	"strings"
 	"sync"
 
 	kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
@@ -40,6 +42,16 @@ import (
 const dbfile = "sqlite.db"
 
 func main() {
+
+	port := flag.Int("port", 8080, "Select the port to run the server on")
+	addr := flag.String("ip", "", "Address to perform the initial network sweep on")
+
+	flag.Parse()
+
+	if len(strings.Split(*addr, "/")) < 2 {
+		log.Fatal("You must pass an address that contains valid CIDR notation, i.e. '192.168.50.1/24'")
+	}
+
 	os.Remove(dbfile) // TODO: remove this once i add more smart interaction with the DB
 	db, err := sql.Open("sqlite3", dbfile)
 	if err != nil {
@@ -49,24 +61,24 @@ func main() {
 	hostsRepo := kyoketsu.NewSQLiteRepo(db)
 	var wg sync.WaitGroup
 	wg.Add(1)
-	go kyoketsu.RunHttpServer(8082, hostsRepo)
+	go kyoketsu.RunHttpServer(*port, hostsRepo)
 
 	if err = hostsRepo.Migrate(); err != nil {
 		log.Fatal(err)
 	}
 	log.Println("SUCCESS ::: SQLite database initiated, and open for writing.")
 
-	hosts, err := kyoketsu.NetSweep(os.Args[1], kyoketsu.RetrieveScanDirectives().Pairs)
+	hosts, err := kyoketsu.NetSweep(*addr, kyoketsu.RetrieveScanDirectives().Pairs)
 	if err != nil {
 		log.Fatal(err)
 	}
 	for i := range hosts {
-		fmt.Printf("%+v\n", hosts[i])
 		_, err := hostsRepo.Create(*hosts[i])
 		if err != nil {
-			log.Fatalf("Couldnt create new entry :( error: %s\n", err)
+			log.Printf("Couldnt create new entry :( error: %s\n", err)
 
 		}
+		fmt.Println("SUCCESS ::: Host found. Adding to the database.")
 
 	}
 	wg.Wait()

+ 2 - 1
cmd/kyoketsu/kyoketsu.go

@@ -91,7 +91,8 @@ func main() {
 				dns, _ := net.LookupAddr(out.IpAddress)
 				out.Fqdn = strings.Join(dns, ", ")
 
-				fmt.Printf("%+v\n", out)
+				fmt.Println(" |-|-|-| :::: HOST FOUND :::: |-|-|-|\n==================||==================\n")
+				fmt.Printf("Hostname: %s\nIPv4 Address: %s\nPing Response?: %v\nListening Ports: %s\n=====================================\n", out.Fqdn, out.IpAddress, out.PingResponse, out.PortString)
 
 			}
 

+ 20 - 26
pkg/local.go

@@ -53,6 +53,19 @@ type IpSubnetMapper struct {
 	Mask        int
 }
 
+type PromptEntry struct {
+	HostAddress    string
+	NetworkAddress string
+	Cidr           string
+	SubnetMask     string
+	InterfaceName  string
+	MacAddress     string
+}
+
+type TuiSelectionFeed struct {
+	Choice []PromptEntry
+}
+
 /*
 Get the next IPv4 address of the address specified in the 'addr' argument,
 
@@ -134,33 +147,12 @@ func GetNetworkAddresses(addr string) (*IpSubnetMapper, error) {
 
 }
 
-type PromptEntry struct {
-	HostAddress    string
-	NetworkAddress string
-	Cidr           string
-	SubnetMask     string
-	InterfaceName  string
-	MacAddress     string
-}
-
-type TuiSelectionFeed struct {
-	Choice []PromptEntry
-}
-
-func matchAddressToMac(ip string, intfs []net.Interface) (*PromptEntry, error) {
-	for i := range intfs {
-		intfsAddr, err := intfs[i].Addrs()
-		if err != nil {
-			return nil, err
-		}
-		for x := range intfsAddr {
-			fmt.Println(intfsAddr[x].String())
-		}
-
-	}
-	return nil, nil
-}
+/*
+Turns a set of network mask bits into a valid IPv4 representation
 
+	    :param ones: number of 1's in the netmask, i.e. 16 == 11111111 11111111 00000000 00000000
+		:param bits: the number of bits that the mask consists of (need to keep this param for ipv6 support later)
+*/
 func bitsToMask(ones int, bits int) string {
 	var bitmask []int
 
@@ -207,6 +199,7 @@ func powerInt(x int, y int) int {
 	return int(math.Pow(float64(x), float64(y)))
 }
 
+// Needs cleanup, but this function populatest a data structure that will be used during TUI program startup
 func RetrieveLocalAddresses() (TuiSelectionFeed, error) {
 	var tuidata TuiSelectionFeed
 	intf, err := net.Interfaces()
@@ -237,6 +230,7 @@ func RetrieveLocalAddresses() (TuiSelectionFeed, error) {
 				}
 			}
 		}
+
 		tuidata.Choice = append(tuidata.Choice, PromptEntry{
 			HostAddress:    ip.String(),
 			NetworkAddress: ip.Mask(net.Mask).String(),