MCPcopy Create free account
hub / github.com/SamNet-dev/snix / writeIPTable

Function writeIPTable

cmd/snix/scan.go:320–342  ·  view source on GitHub ↗
(w interface{ Write(p []byte) (int, error) }, all, ranked []scanner.IPResult)

Source from the content-addressed store, hash-verified

318}
319
320func writeIPTable(w interface{ Write(p []byte) (int, error) }, all, ranked []scanner.IPResult) error {
321 tw := tabwriter.NewWriter(w, 0, 2, 2, ' ', 0)
322
323 reachable := 0
324 for _, r := range all {
325 if r.Reachable {
326 reachable++
327 }
328 }
329 fmt.Fprintf(w, "Reachable: %d / %d\n\n", reachable, len(all))
330 if len(ranked) == 0 {
331 fmt.Fprintln(w, "No reachable IPs. Network issue?")
332 return nil
333 }
334 // Sort displayed-ranked by RTT already, but keep it explicit.
335 sort.Slice(ranked, func(i, j int) bool { return ranked[i].RTT < ranked[j].RTT })
336 fmt.Fprintln(tw, "RANK\tIP\tRTT")
337 for i, r := range ranked {
338 fmt.Fprintf(tw, "%d\t%s\t%s\n",
339 i+1, r.IP, r.RTT.Round(time.Millisecond))
340 }
341 return tw.Flush()
342}
343
344func min(a, b int) int {
345 if a < b {

Callers 2

newScanIPCmdFunction · 0.85
newScanAllCmdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected