Skip to content

Commit

Permalink
fix: do not crash if wifi is not connected (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sralloza authored Dec 28, 2023
1 parent 8f297c7 commit f021951
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (f *Finder) Run(args Args) error {
}
fmt.Printf("Found %d IP addresses\n", len(ipv4List))

fmt.Printf("Zear IP addresses (user: %s)...\n", args.User)
fmt.Printf("Scanning IP addresses (user: %s)...\n", args.User)
start := time.Now()
f.findArgs = args
f.totalIPs = ipv4List
Expand Down
10 changes: 7 additions & 3 deletions pkg/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (n *networkingManager) getIfaceToConMap() (map[string]string, error) {
return nil, fmt.Errorf("error getting network interfaces: %w", err)
}

r := regexp.MustCompile(`([\w ]+)\s+([a-z0-9-]+)\s+(\w+)\s+(\w+)`)
r := regexp.MustCompile(`([\w ]+)\s+([a-z0-9-]+)\s+(\w+)\s+([\w-]+)`)

lines := strings.Split(stdout, "\n")
data := make(map[string]string)
Expand All @@ -156,9 +156,13 @@ func (n *networkingManager) getIfaceToConMap() (map[string]string, error) {
}
matches := r.FindStringSubmatch(line)
if len(matches) < 5 {
return nil, fmt.Errorf("error parsing network interfaces: %s", line)
return nil, fmt.Errorf("error parsing network interfaces: '%s'", line)
}
// Detect if the interface is not connected
if matches[4] == "--" {
n.log.Debug().Str("name", matches[3]).Str("uuid", matches[2]).Msg("Skipping connection, no device connected")
continue
}

data[matches[4]] = matches[2]
}

Expand Down

0 comments on commit f021951

Please sign in to comment.