Skip to content

Commit

Permalink
Merge pull request #20 from praetorian-inc/readme-update
Browse files Browse the repository at this point in the history
add example library import
  • Loading branch information
praetorian-thendrickson committed Jul 17, 2023
2 parents 297329f + f22280d commit 61fcd6d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a href="#installation">Installation</a> •
<a href="#usage">Usage</a> •
<a href="#running-fingerprintx">Running fingerprintx</a> •
<a href="#using-as-a-library">Using as a library</a> •
<a href="#why-not-nmap">Why not nmap?</a> •
<a href="#notes">Notes</a> •
<a href="#acknowledgements">Acknowledgements</a>
Expand Down Expand Up @@ -169,6 +170,9 @@ $ cat input.txt | fingerprintx --json
{"host":"telehack.com","ip":"64.13.139.230","port":23,"service":"telnet","transport":"tcp","metadata":{"serverData":"fffb03"}}
```

# Using as a library
`fingerprintx` can be imported into your project to scan for services on open ports. Example code on how one might do this is provided [here in the examples directory](examples/scan.go). Build with `go build scan.go`. Another file that might be of use as a reference when importing `fingerprintx` into your own project is the [command line runner](pkg/runner/root.go).

# Why Not Nmap?
[Nmap](https://nmap.org/) is the standard for network scanning. Why use `fingerprintx` instead of nmap? The main two reasons are:

Expand Down
41 changes: 41 additions & 0 deletions examples/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"log"
"net/netip"
"time"

"github.com/praetorian-inc/fingerprintx/pkg/plugins"
"github.com/praetorian-inc/fingerprintx/pkg/scan"
)

func main() {
// setup the scan config (mirrors command line options)
fxConfig := scan.Config{
DefaultTimeout: time.Duration(2) * time.Second,
FastMode: false,
Verbose: false,
UDP: false,
}

// create a target list to scan
ip, _ := netip.ParseAddr("146.148.61.165")
target := plugins.Target{
Address: netip.AddrPortFrom(ip, 443),
Host: "praetorian.com",
}
targets := make([]plugins.Target, 1)
targets = append(targets, target)

// run the scan
results, err := scan.ScanTargets(targets, fxConfig)
if err != nil {
log.Fatalf("error: %s\n", err)
}

// process the results
for _, result := range results {
fmt.Printf("%s:%d (%s/%s)\n", result.Host, result.Port, result.Transport, result.Protocol)
}
}

0 comments on commit 61fcd6d

Please sign in to comment.