()
| 72 | } |
| 73 | |
| 74 | func main() { |
| 75 | initFlags() |
| 76 | flag.Parse() |
| 77 | |
| 78 | if *hostnamePtr != DefaultHostname { |
| 79 | hostnameType = newHostname |
| 80 | } else if *randHostnamePtr { |
| 81 | hostnameType = randHostname |
| 82 | } else { |
| 83 | hostnameType = def |
| 84 | } |
| 85 | |
| 86 | fmt.Fprintln(os.Stderr, Banner) |
| 87 | |
| 88 | interfaces, _ := net.Interfaces() |
| 89 | logger.Println("======== Starting RESPOUNDER ========") |
| 90 | logger.Printf("List of all interfaces: \n %+v\n", interfaces) |
| 91 | |
| 92 | var resultMap []map[string]string |
| 93 | |
| 94 | // send probe on specific interface if -interface flag is set |
| 95 | if *interfacePtr != "" { |
| 96 | inf, err := net.InterfaceByName(*interfacePtr) |
| 97 | if err != nil { |
| 98 | fmt.Printf("Invalid interface '%s'. List of valid interfaces are:\n", *interfacePtr) |
| 99 | for _, inf := range interfaces { |
| 100 | fmt.Println("- " + inf.Name) |
| 101 | } |
| 102 | return |
| 103 | } |
| 104 | detailsMap := checkResponderOnInterface(*inf) |
| 105 | if len(detailsMap) > 0 { |
| 106 | resultMap = append(resultMap, detailsMap) |
| 107 | } |
| 108 | } else { // send probes from all interfaces if -interface flag isn't set |
| 109 | for _, inf := range interfaces { |
| 110 | detailsMap := checkResponderOnInterface(inf) |
| 111 | if len(detailsMap) > 0 { |
| 112 | resultMap = append(resultMap, detailsMap) |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if *debugPtr { |
| 118 | fmt.Fprintln(os.Stderr, "Debug file 'debug.log' created.") |
| 119 | } |
| 120 | |
| 121 | if *jsonPtr { |
| 122 | resultJSON, _ := json.Marshal(resultMap) |
| 123 | fmt.Println(string(resultJSON)) |
| 124 | } |
| 125 | logger.Println("======== Ending RESPOUNDER Session ========") |
| 126 | } |
| 127 | |
| 128 | // Test presence of responder on a given interface |
| 129 | func checkResponderOnInterface(inf net.Interface) map[string]string { |
nothing calls this directly
no test coverage detected