Skip to content

Commit

Permalink
ARP live rescan timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
v-byte-cpu committed Mar 28, 2021
1 parent 2d8d6a1 commit 52c5dd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ wait 5 seconds before exiting to receive delayed reply packets, by default `sx`
./sx arp --exit-delay 5s 192.168.0.1/24
```

Live scan mode that rescans network every second:
Live scan mode that rescans network every 10 seconds:

```
./sx arp 192.168.0.1/24 --live
./sx arp 192.168.0.1/24 --live 10s
```

### TCP scan
Expand Down Expand Up @@ -286,13 +286,13 @@ As an example of scan composition, you can combine ARP and TCP SYN scans to crea
Start live ARP scan and save results to `arp.cache` file:

```
./sx arp 192.168.0.1/24 --live --json | tee arp.cache
./sx arp 192.168.0.1/24 --live 10s --json | tee arp.cache
```

In another terminal start TCP SYN scan:

```
while true; do cat arp.cache | ./sx tcp -p 1-65535 192.168.0.1/24 --json 2> /dev/null; sleep 10; done
while true; do cat arp.cache | ./sx tcp -p 1-65535 192.168.0.1/24 --json 2> /dev/null; sleep 30; done
```

## Usage help
Expand Down
20 changes: 14 additions & 6 deletions command/arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import (
"github.com/v-byte-cpu/sx/pkg/scan/arp"
)

var arpLiveModeFlag bool
var (
cliARPLiveTimeoutFlag string
cliARPLiveTimeout time.Duration
)

func init() {
arpCmd.Flags().BoolVar(&arpLiveModeFlag, "live", false, "enable live mode")
arpCmd.Flags().StringVar(&cliARPLiveTimeoutFlag, "live", "", "enable live mode")
rootCmd.AddCommand(arpCmd)
}

Expand All @@ -32,6 +35,12 @@ var arpCmd = &cobra.Command{
}
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
if len(cliARPLiveTimeoutFlag) > 0 {
cliARPLiveTimeout, err = time.ParseDuration(cliARPLiveTimeoutFlag)
}
return
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
var r *scan.Range
if r, err = parseScanRange(args[0]); err != nil {
Expand All @@ -45,7 +54,7 @@ var arpCmd = &cobra.Command{
if logger, err = getLogger("arp", os.Stdout); err != nil {
return err
}
if arpLiveModeFlag {
if cliARPLiveTimeout > 0 {
logger = log.NewUniqueLogger(logger)
}

Expand All @@ -61,9 +70,8 @@ var arpCmd = &cobra.Command{

func newARPScanMethod(ctx context.Context) *arp.ScanMethod {
var reqgen scan.RequestGenerator = scan.NewIPRequestGenerator(scan.NewIPGenerator())
if arpLiveModeFlag {
// TODO rescanTimeout option
reqgen = scan.NewLiveRequestGenerator(reqgen, 1*time.Second)
if cliARPLiveTimeout > 0 {
reqgen = scan.NewLiveRequestGenerator(reqgen, cliARPLiveTimeout)
}
pktgen := scan.NewPacketMultiGenerator(arp.NewPacketFiller(), runtime.NumCPU())
psrc := scan.NewPacketSource(reqgen, pktgen)
Expand Down

0 comments on commit 52c5dd7

Please sign in to comment.