Brijesh's Git Server — network-scan @ e6d5a05b95b3a6a42e789e60e798021569e2bd3c

main.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
package main

import (
	"fmt"
	"log"
	"os"

	"network-scan/arp"
	"network-scan/database"
	"network-scan/oui"
	"network-scan/utils"
)

const dbPath string = "./oui.db"

func init() {
	err := database.CreateDbIfNotExists(dbPath)
	if err != nil {
		log.Fatalf("Error creating database file: %v", err)
	}

	db, err := database.New(dbPath)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer db.Close()

	err = db.CreateOuiTable()
	if err != nil {
		log.Fatalf("Error creating table: %v", err)
	}
}

func main() {
	db, err := database.New(dbPath)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	} else {
		utils.PrintInColor("Database opened successfully", 28)
	}
	defer db.Close()

	utils.ConfirmBeforeRunning("Do you want to seed sqlite from IEEE data?", func() {
		file, err := os.Open("standards-oui.ieee.org.txt")
		if err != nil {
			log.Fatalf("Error opening file: %v", err)
		}
		defer file.Close()

		oui.ScanDataFromTextFile("/Users/brijesh/projects/ongoing/network-scan/standards-oui.ieee.org.txt", db)
		utils.PrintInColor("OUI data imported successfully", 28)
	})

	utils.ConfirmBeforeRunning("Do you want to scan for devices in your network?", func() {
		devices, err := arp.GetDevices()
		if err != nil {
			fmt.Println("Error:", err)
			return
		}

		fmt.Println("Devices found:")
		for _, device := range devices {
			fmt.Printf("IP: %s, MAC: %s\n", device.IP, device.MAC)
		}
	})

}