Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running scan: exit status 1 #129

Open
wowlikon opened this issue Apr 22, 2024 · 1 comment
Open

Error running scan: exit status 1 #129

wowlikon opened this issue Apr 22, 2024 · 1 comment

Comments

@wowlikon
Copy link

wowlikon commented Apr 22, 2024

When i run this code

package main

import (
	"context"
	"fmt"
	"net"
	"time"

	"github.com/Ullaakut/nmap/v3"
)

func tcpGather(ip string, ports []string) map[string]bool {
	results := make(map[string]bool)
	for _, port := range ports {
		address := net.JoinHostPort(ip, port)
		conn, err := net.DialTimeout("tcp", address, time.Second/2)
		if err != nil {
			results[port] = false
		} else {
			if conn != nil {
				results[port] = true
				_ = conn.Close()
			} else {
				results[port] = false
			}
		}
	}
	return results
}

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	// Create a new nmap scanner
	scanner, err := nmap.NewScanner(
		ctx,
		nmap.WithTargets("192.168.0.0/24"), // Specify the network range to scan
		nmap.WithFastMode(),                // Enable fast mode
	)

	if err != nil {
		fmt.Println("Error creating scanner:", err)
		return
	}

	// Run the scan
	result, _, err := scanner.Run()

	if err != nil {
		fmt.Println("Error running scan:", err)
		return
	}

	// Print the results
	for _, host := range result.Hosts {
		if len(host.Addresses) == 0 {
			continue
		}

		ip := host.Addresses[0].Addr

		name := "Unknown"
		if len(host.Hostnames) == 1 {
			name = host.Hostnames[0].Name
		} else if len(host.Hostnames) > 1 {
			name = "["
			for _, current_name := range host.Hostnames {
				name += current_name.Name + ", "
			}
			name += "]"
		}

		mac := ""
		if len(host.Addresses) > 1 {
			mac = host.Addresses[1].Addr
		}

		fmt.Printf(
			"NAME: %s\nIP: %s\nMAC: %s\n",
			name, ip, mac,
		)

		ports := tcpGather(ip,
			[]string{"20", "21", "22", "80", "135", "139", "143", "443", "445", "3020", "3306", "3389", "8022", "8080"},
		)
		if len(ports) != 0 {
			fmt.Println("PORTS:")
			for port, status := range ports {
				fmt.Printf("\t%-5s: %5t\n", string(port), status)
			}
		}
		fmt.Print("\n\n")
	}
}

result: Error running scan: exit status 1
tested on windows 10 and windows 11

@Ullaakut
Copy link
Owner

Ullaakut commented May 1, 2024

Hi @wowlikon ! Which version of nmap do you use? Is it available in your PATH?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants