Comments (6)
Hey @TheSecEng!
Sorry about the delay. This looks like a good implementation! Thank you so much!
It seems like a good first step to provide utility to people who might want to use it, but I'm curious how people will end up integrating it into their apps.
Either way, I'd love to see it in the form of a PR and to work on it together!
from nmap.
Hey @TheSecEng!
Sorry about the delay. This looks like a good implementation! Thank you so much!
It seems like a good first step to provide utility to people who might want to use it, but I'm curious how people will end up integrating it into their apps.
Either way, I'd love to see it in the form of a PR and to work on it together!
I've actually got a use case right now that I will be using this for once its finished. So there is definitely reasons to get this running.
from nmap.
Have you had time to look at this more ? If not, I’ll start looking into how to add this properly. It’s be nice to have.
from nmap.
Hey @TheSecEng I didn't have time as of now, I've been working on other projects, but if you're interested in picking this one up I'd love to give you any help you need :)
from nmap.
@Ullaakut you got it!
from nmap.
@Ullaakut Thoughts? As I wasn't fully understanding of channels. This would be a solution I propose.
However, if this doesn't meet the full need. I'll need to research further into channels and take time to really understand them.
I think this method avoids some of the pains of using channels, but potentially at the sacrifice of easily putting the results into a private var then exposing it.
But then again, it would require Run()
to be modified as well. Those updates being minimal.
// Scanner represents an Nmap scanner.
type Scanner struct {
Cmd *exec.Cmd
args []string
binaryPath string
ctx context.Context
portFilter func(Port) bool
hostFilter func(Host) bool
Stderr, Stdout bufio.Scanner
}
// RunAsync runs nmap asynchronously and returns error.
func (s *Scanner) RunAsync() error {
// Enable XML output
s.args = append(s.args, "-oX")
// Get XML output in stdout instead of writing it in a file
s.args = append(s.args, "-")
s.Cmd = exec.Command(s.binaryPath, s.args...)
stderr, err := s.Cmd.StderrPipe()
if err != nil {
return err
}
stdout, err := s.Cmd.StdoutPipe()
if err != nil {
return err
}
s.Stdout = *bufio.NewScanner(stdout)
s.Stderr = *bufio.NewScanner(stderr)
if err := s.Cmd.Start(); err != nil {
return err
}
go func() {
select {
case <-s.ctx.Done():
s.Cmd.Process.Kill()
}
}()
return nil
}
Example
package main
import (
"encoding/json"
"fmt"
"log"
"strings"
"github.com/Ullaakut/nmap"
)
func main() {
var resultBytes []byte
var errorBytes []byte
s, err := nmap.NewScanner(
nmap.WithTargets("google.com", "facebook.com", "youtube.co1m"),
nmap.WithPorts("80,443,843"),
)
if err != nil {
log.Fatalf("unable to create nmap scanner: %v", err)
}
if err := s.RunAsync(); err != nil {
panic(err)
}
go func() {
for s.Stdout.Scan() {
fmt.Println(s.Stdout.Text())
resultBytes = append(resultBytes, s.Stdout.Bytes()...)
}
}()
go func() {
for s.Stderr.Scan() {
errorBytes = append(errorBytes, s.Stderr.Bytes()...)
}
}()
if err := s.Cmd.Wait(); err != nil {
panic(err)
}
results, err := nmap.Parse(resultBytes)
results.NmapErrors = strings.Split(string(errorBytes), "\n")
if err != nil {
panic(err)
}
temp, err := json.MarshalIndent(results, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("%s\n", temp)
}
from nmap.
Related Issues (20)
- No -PN support HOT 1
- RunWithProgress goes from 100% to 0% and back again HOT 2
- Still timing out after 5 minutes HOT 2
- RunAsync lost s.cmd.Wait() ? HOT 1
- How should I get the json output of the Run HOT 4
- How i use this in windows10 , i have go build , but can't user, please tell me, thank you ! HOT 2
- Run the nmap scanned with custom arguments HOT 3
- Run nmap without runtime interaction HOT 6
- If the service recognises that there is a "?", how to deal with it? HOT 4
- Memory Usage is too high when using Progress(...) HOT 6
- XML to JSON support HOT 1
- The basic_scan_async demo cannot output the results in real time on the console HOT 3
- unable to create nmap scanner: nmap binary was not found HOT 2
- How we can do the OS scan with root privileges HOT 2
- unable to parse nmap output, see warnings for details: XML syntax error on line 7: unexpected EOF HOT 12
- nmap.WithOSDetection() HOT 1
- what's the equivalent of `-n` and `--defeat-rst-ratelimit` flag? HOT 1
- Example should be updated
- Error running scan: exit status 1 HOT 1
- when I run the code whit WithScripts hava warning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nmap.