Go-Nmap is a Go library designed for parsing Nmap XML data into structured and easy-to-use Go structs. It simplifies the process of working with Nmap scan results programmatically.
- Comprehensive mapping of Nmap XML data to Go structs.
- Easy integration with Go applications.
- Supports various Nmap scan data including host details, ports, services, OS information, and more.
To use Go-Nmap in your project, you can install it using go get:
$ go get github.com/tomsteele/go-nmapThe library's documentation is available at GoDoc.
Here is an example of how to use Go-Nmap to parse Nmap XML data:
package main
import (
"fmt"
"io/ioutil"
"github.com/tomsteele/go-nmap"
)
func main() {
// Load the XML data from a file
data, err := ioutil.ReadFile("scan.xml")
if err != nil {
panic(err)
}
// Parse the XML data
nmapRun, err := nmap.Parse(data)
if err != nil {
panic(err)
}
// Access parsed data
fmt.Printf("Nmap Scanner: %s\n", nmapRun.Scanner)
fmt.Printf("Number of Hosts: %d\n", len(nmapRun.Hosts))
}The library provides a rich set of types and functions for accessing Nmap scan data. Below is a summary of the primary types and their purposes:
NmapRun: Contains all data for a single Nmap scan.- Example:
nmapRun.Hoststo access scanned hosts.
- Example:
Host: Represents a single host in the scan results.- Example:
host.Addressesto get the host's IP addresses.
- Example:
Port: Provides details about scanned ports.- Example:
port.Serviceto get the service running on the port.
- Example:
Os: Contains fingerprinted operating system details.
Parse(content []byte) (*NmapRun, error): Parses Nmap XML data into anNmapRunstruct.
type Host struct {
StartTime Timestamp `xml:"starttime,attr" json:"starttime"`
EndTime Timestamp `xml:"endtime,attr" json:"endtime"`
Status Status `xml:"status" json:"status"`
Addresses []Address `xml:"address" json:"addresses"`
Ports []Port `xml:"ports>port" json:"ports"`
Os Os `xml:"os" json:"os"`
}type Port struct {
Protocol string `xml:"protocol,attr" json:"protocol"`
PortId int `xml:"portid,attr" json:"id"`
State State `xml:"state" json:"state"`
Service Service `xml:"service" json:"service"`
}We welcome contributions from the community! If you find a bug, have a feature request, or want to contribute code:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request with a detailed explanation of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.