### GuessProtocol - Get Default Protocol for Port Source: https://context7.com/lcvvvv/gonmap/llms.txt Returns the expected protocol name for a given port number based on Nmap's services database. ```APIDOC ## GuessProtocol ### Description Returns the expected protocol name for a given port number based on Nmap's services database. ### Parameters - **port** (int) - Required - The port number to look up. ### Response - **protocol** (string) - The standardized protocol name (e.g., "ssh", "http"). ``` -------------------------------- ### Initialize Gonmap Scanner Source: https://context7.com/lcvvvv/gonmap/llms.txt Creates a new scanner instance with default probe database settings. This is the entry point for all network scanning operations. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() scanner.SetTimeout(3 * time.Second) status, response := scanner.ScanTimeout("192.168.1.100", 22, 30*time.Second) if status == gonmap.Matched && response != nil { fmt.Printf("Service: %s\n", response.FingerPrint.Service) fmt.Printf("Product: %s\n", response.FingerPrint.ProductName) fmt.Printf("Version: %s\n", response.FingerPrint.Version) } } ``` -------------------------------- ### Perform Port Scanning with Timeouts Source: https://context7.com/lcvvvv/gonmap/llms.txt Demonstrates how to scan multiple ports on a host using ScanTimeout, which provides granular control over individual connection attempts. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() ports := []int{22, 80, 443, 3306, 6379} host := "target.example.com" for _, port := range ports { status, response := scanner.ScanTimeout(host, port, 30*time.Second) switch status { case gonmap.Matched: fp := response.FingerPrint fmt.Printf("[%d] %s - %s %s\n", port, fp.Service, fp.ProductName, fp.Version) case gonmap.Open: fmt.Printf("[%d] Open but service not identified\n", port) case gonmap.Closed: fmt.Printf("[%d] Closed\n", port) case gonmap.NotMatched: fmt.Printf("[%d] Open but no fingerprint match\n", port) } } } ``` -------------------------------- ### Add Custom Fingerprint Rules with AddMatch Source: https://context7.com/lcvvvv/gonmap/llms.txt Demonstrates how to extend the scanner's capabilities by adding custom regex-based matching rules for proprietary services. It uses the AddMatch method to define patterns that identify product names and versions. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() // Add custom match rule for a proprietary service // Format: service_name m|regex_pattern| p/product_name/ v/version/ scanner.AddMatch("TCP_GetRequest", `myapp m|^MyApp Server v([\d.]+)| p/MyApp/ v/$1/`) scanner.AddMatch("TCP_NULL", `customdb m|^CUSTOMDB\x00\x01| p/CustomDB Server/`) status, response := scanner.ScanTimeout("192.168.1.100", 9000, 30*time.Second) if status == gonmap.Matched { fmt.Printf("Detected: %s %s\n", response.FingerPrint.ProductName, response.FingerPrint.Version) } } ``` -------------------------------- ### Gonmap: Scan Port Status and Handle Responses in Go Source: https://context7.com/lcvvvv/gonmap/llms.txt This Go code snippet demonstrates how to use the gonmap library to scan a specific port on an IP address with a configurable timeout. It handles various status constants (Closed, Open, Matched, NotMatched, Unknown) returned by the scan, providing specific output for each case. The response object contains fingerprint information for matched services. It also shows how to print the string representation of the status. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() status, response := scanner.ScanTimeout("192.168.1.1", 8080, 30*time.Second) // Handle all possible status values switch status { case gonmap.Closed: fmt.Println("Port is closed or filtered") case gonmap.Open: fmt.Println("Port is open but no response received") case gonmap.Matched: fmt.Printf("Service identified: %s\n", response.FingerPrint.Service) case gonmap.NotMatched: fmt.Println("Response received but no fingerprint matched") if response != nil { fmt.Printf("Raw response: %q\n", response.Raw[:min(50, len(response.Raw))]) } case gonmap.Unknown: fmt.Println("Unknown scan status") } // Status also implements String() method fmt.Printf("Status string: %s\n", status.String()) } func min(a, b int) int { if a < b { return a } return b } ``` -------------------------------- ### Accessing Response and FingerPrint Data Source: https://context7.com/lcvvvv/gonmap/llms.txt Demonstrates how to extract detailed metadata from a scan result, including TLS status, raw response data, and parsed fingerprint information like product name and version. ```go package main import ( "encoding/json" "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() status, response := scanner.ScanTimeout("192.168.1.1", 443, 30*time.Second) if status == gonmap.Matched && response != nil { fp := response.FingerPrint result := map[string]string{ "service": fp.Service, "product": fp.ProductName, "version": fp.Version, } jsonOutput, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(jsonOutput)) } } ``` -------------------------------- ### Configure Custom Logger Source: https://context7.com/lcvvvv/gonmap/llms.txt Allows integration of a custom logger to capture scan operations and debugging information into external files or streams. ```go package main import ( "log" "os" "time" "github.com/lcvvvv/gonmap" ) func main() { logFile, _ := os.Create("gonmap.log") customLogger := log.New(logFile, "[SCAN] ", log.Ldate|log.Ltime|log.Lmicroseconds) gonmap.SetLogger(customLogger) scanner := gonmap.New() scanner.ScanTimeout("192.168.1.1", 22, 30*time.Second) logFile.Close() } ``` -------------------------------- ### Execute Basic Scan Source: https://context7.com/lcvvvv/gonmap/llms.txt Performs a standard service detection scan using the scanner's internal timeout configuration. This is useful for simpler, non-context-sensitive scanning tasks. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() scanner.SetTimeout(5 * time.Second) status, response := scanner.Scan("192.168.1.1", 80) if status == gonmap.Matched { fmt.Printf("Detected: %s\n", response.FingerPrint.Service) fmt.Printf("TLS: %v\n", response.TLS) fmt.Printf("Raw Response Length: %d bytes\n", len(response.Raw)) } } ``` -------------------------------- ### Configure Scanner Timeout Source: https://context7.com/lcvvvv/gonmap/llms.txt Sets the default connection timeout for the scanner instance, allowing adjustment for network latency. ```go package main import ( "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() scanner.SetTimeout(1 * time.Second) scanner.SetTimeout(10 * time.Second) status, response := scanner.ScanTimeout("192.168.1.1", 443, 30*time.Second) _ = status _ = response } ``` -------------------------------- ### Normalize Protocol Names with FixProtocol Source: https://context7.com/lcvvvv/gonmap/llms.txt Converts raw or non-standard service names into standardized protocol identifiers. This ensures consistent reporting across different scan results. ```go package main import ( "fmt" "github.com/lcvvvv/gonmap" ) func main() { rawProtocols := []string{ "ssl/http", "ms-wbt-server", "microsoft-ds", "ms-sql-s", "http-proxy", "oracle-tns", } for _, raw := range rawProtocols { fixed := gonmap.FixProtocol(raw) fmt.Printf("%s -> %s\n", raw, fixed) } } ``` -------------------------------- ### Enable Deep Service Identification Source: https://context7.com/lcvvvv/gonmap/llms.txt Activates deep scanning mode to perform intensive version detection using all available probes, similar to Nmap's -sV flag. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { scanner := gonmap.New() scanner.OpenDeepIdentify() scanner.SetTimeout(5 * time.Second) status, response := scanner.ScanTimeout("192.168.1.1", 8080, 60*time.Second) if status == gonmap.Matched { fp := response.FingerPrint fmt.Printf("Service: %s\n", fp.Service) fmt.Printf("Product: %s\n", fp.ProductName) fmt.Printf("Version: %s\n", fp.Version) fmt.Printf("OS: %s\n", fp.OperatingSystem) fmt.Printf("Device: %s\n", fp.DeviceType) fmt.Printf("Probe Used: %s\n", fp.ProbeName) } } ``` -------------------------------- ### FixProtocol - Normalize Protocol Names Source: https://context7.com/lcvvvv/gonmap/llms.txt Converts raw service names to standardized protocol identifiers. ```APIDOC ## FixProtocol ### Description Converts raw service names to standardized protocol identifiers (e.g., `ms-wbt-server` to `rdp`). ### Parameters - **rawName** (string) - Required - The raw protocol string to normalize. ### Response - **normalizedName** (string) - The standardized protocol identifier. ``` -------------------------------- ### Guess Protocol for Port Source: https://context7.com/lcvvvv/gonmap/llms.txt Retrieves the expected protocol name for a given port number using the built-in Nmap services database. This is useful for identifying common services before performing a full scan. ```go package main import ( "fmt" "github.com/lcvvvv/gonmap" ) func main() { ports := []int{22, 80, 443, 3306, 5432, 6379, 27017} for _, port := range ports { protocol := gonmap.GuessProtocol(port) fmt.Printf("Port %d -> %s\n", port, protocol) } } ``` -------------------------------- ### AddMatch - Add Custom Fingerprint Rules Source: https://context7.com/lcvvvv/gonmap/llms.txt Adds custom fingerprint matching rules to an existing probe for detecting additional services or custom applications. ```APIDOC ## AddMatch ### Description Adds custom fingerprint matching rules to an existing probe for detecting additional services or custom applications. ### Method Function Call ### Parameters - **probeName** (string) - Required - The name of the probe to attach the rule to. - **rule** (string) - Required - The regex-based matching rule string. ### Request Example scanner.AddMatch("TCP_GetRequest", `myapp m|^MyApp Server v([\d.]+)| p/MyApp/ v/$1/`) ``` -------------------------------- ### SetFilter - Configure Probe Rarity Filter Source: https://context7.com/lcvvvv/gonmap/llms.txt Reinitializes the scanner with a specified probe rarity filter level (1-9). ```APIDOC ## SetFilter ### Description Reinitializes the scanner with a specified probe rarity filter level (1-9). Lower values use fewer, more common probes for faster scanning. ### Parameters - **level** (int) - Required - Rarity level between 1 and 9. ``` -------------------------------- ### Configure Probe Rarity Filter Source: https://context7.com/lcvvvv/gonmap/llms.txt Adjusts the scanner's probe rarity level to balance speed and accuracy. Lower values prioritize common probes, while higher values include more obscure checks. ```go package main import ( "fmt" "time" "github.com/lcvvvv/gonmap" ) func main() { gonmap.SetFilter(5) fmt.Printf("Total Probes: %d\n", gonmap.ProbesCount) fmt.Printf("Used Probes: %d\n", gonmap.UsedProbesCount) scanner := gonmap.New() scanner.ScanTimeout("192.168.1.1", 80, 10*time.Second) } ``` -------------------------------- ### SetLogger - Configure Custom Logger Source: https://context7.com/lcvvvv/gonmap/llms.txt Sets a custom logger for debugging and monitoring scan operations. ```APIDOC ## SetLogger ### Description Sets a custom logger for debugging and monitoring scan operations. ### Parameters - **logger** (*log.Logger) - Required - A standard Go logger instance. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.