@@ -25,7 +25,7 @@ const (
25
25
'-'
26
26
`
27
27
28
- Version = 1.1
28
+ Version = 1.2
29
29
TimeoutSec = 3
30
30
BcastAddr = "224.0.0.252"
31
31
LLMNRPort = 5355
@@ -47,18 +47,23 @@ var (
47
47
48
48
// argument flags
49
49
jsonPtr = flag .Bool ("json" , false ,
50
- `Prints a JSON to STDOUT if a responder is detected on
51
- the network. Other text is sent to STDERR` )
50
+ `Prints a JSON to STDOUT if a responder is detected in the subnet.
51
+ Other text is sent to STDERR` )
52
52
53
53
debugPtr = flag .Bool ("debug" , false ,
54
54
`Creates a debug.log file with a trace of the program` )
55
55
56
56
hostnamePtr = flag .String ("hostname" , DefaultHostname ,
57
57
`Hostname to search for` )
58
+
58
59
randHostnamePtr = flag .Bool ("rhostname" , false ,
59
60
`Searches for a hostname comprised of random string instead
60
61
of the default hostname ("` + DefaultHostname + `")` )
61
62
63
+ interfacePtr = flag .String ("interface" , "" ,
64
+ `Interface where responder will be searched (eg. eth0).
65
+ Not specifying this flag will search on all interfaces.` )
66
+
62
67
hostnameType byte
63
68
)
64
69
@@ -70,7 +75,7 @@ func main() {
70
75
initFlags ()
71
76
flag .Parse ()
72
77
73
- if * hostnamePtr != "aweirdcomputername" {
78
+ if * hostnamePtr != DefaultHostname {
74
79
hostnameType = newHostname
75
80
} else if * randHostnamePtr {
76
81
hostnameType = randHostname
@@ -86,11 +91,27 @@ func main() {
86
91
87
92
var resultMap []map [string ]string
88
93
89
- for _ , inf := range interfaces {
90
- detailsMap := checkResponderOnInterface (inf )
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 )
91
105
if len (detailsMap ) > 0 {
92
106
resultMap = append (resultMap , detailsMap )
93
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
+ }
94
115
}
95
116
96
117
if * debugPtr {
@@ -157,10 +178,9 @@ func sendLLMNRProbe(ip net.IP) string {
157
178
158
179
conn , err := net .ListenUDP ("udp" , & net.UDPAddr {IP : ip })
159
180
if err != nil {
160
- fmt .Println ( "Couldn't bind to a UDP interface. Bailing out! " )
181
+ fmt .Printf ( "Could not bind to the interface. Is it disabled? " )
161
182
logger .Printf ("Bind error: %+v\n Source IP: %v\n " , err , ip )
162
- fmt .Println (err )
163
- logger .Printf ("LLMNR request payload was: %x\n " , llmnrRequest )
183
+ return responderIP // return with IP = ''
164
184
}
165
185
166
186
defer conn .Close ()
@@ -180,7 +200,7 @@ func sendLLMNRProbe(ip net.IP) string {
180
200
return responderIP
181
201
}
182
202
183
- // Calculate random hostname by taking random lenght
203
+ // Calculate random hostname by taking random length
184
204
// of the SHA1 of current time.
185
205
func randomHostname () string {
186
206
currentTime := time .Now ().Format ("2006-01-02 15:04:05" )
@@ -209,7 +229,7 @@ func getValidIPv4Addr(addrs []net.Addr) net.IP {
209
229
func initFlags () {
210
230
flag .Usage = func () {
211
231
fmt .Fprintf (os .Stderr , "Respounder version %1.1f\n " , Version )
212
- fmt .Fprintf (os .Stderr , "Usage: $ respounder [-json] [-debug] [-hostname testhostname | -rhostname]" )
232
+ fmt .Fprintf (os .Stderr , "Usage: $ respounder [-json] [-debug] [-interface <iface>] [- hostname <name> | -rhostname]" )
213
233
fmt .Fprintf (os .Stderr , "\n \n Flags:\n " )
214
234
flag .PrintDefaults ()
215
235
}
0 commit comments