Skip to content

Commit ed86448

Browse files
author
Code Express
committed
Added ability to specify interface via flag (Fixes #4).\nA disconnected/disabled windows interface will now report it and move on to next interface instead of crashing (Fixes #5)
1 parent 6d505eb commit ed86448

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Flags:
6767
the network. Other text is sent to STDERR
6868
-debug
6969
Creates a debug.log file with a trace of the program
70+
-interface string
71+
Interface where responder will be searched (eg. eth0).
72+
Not specifying this flag will search on all interfaces.
7073
-hostname string
7174
Hostname to search for (default "aweirdcomputername")
7275
-rhostname

respounder.go

+31-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
'-'
2626
`
2727

28-
Version = 1.1
28+
Version = 1.2
2929
TimeoutSec = 3
3030
BcastAddr = "224.0.0.252"
3131
LLMNRPort = 5355
@@ -47,18 +47,23 @@ var (
4747

4848
// argument flags
4949
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`)
5252

5353
debugPtr = flag.Bool("debug", false,
5454
`Creates a debug.log file with a trace of the program`)
5555

5656
hostnamePtr = flag.String("hostname", DefaultHostname,
5757
`Hostname to search for`)
58+
5859
randHostnamePtr = flag.Bool("rhostname", false,
5960
`Searches for a hostname comprised of random string instead
6061
of the default hostname ("`+DefaultHostname+`")`)
6162

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+
6267
hostnameType byte
6368
)
6469

@@ -70,7 +75,7 @@ func main() {
7075
initFlags()
7176
flag.Parse()
7277

73-
if *hostnamePtr != "aweirdcomputername" {
78+
if *hostnamePtr != DefaultHostname {
7479
hostnameType = newHostname
7580
} else if *randHostnamePtr {
7681
hostnameType = randHostname
@@ -86,11 +91,27 @@ func main() {
8691

8792
var resultMap []map[string]string
8893

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)
91105
if len(detailsMap) > 0 {
92106
resultMap = append(resultMap, detailsMap)
93107
}
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+
}
94115
}
95116

96117
if *debugPtr {
@@ -157,10 +178,9 @@ func sendLLMNRProbe(ip net.IP) string {
157178

158179
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: ip})
159180
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? ")
161182
logger.Printf("Bind error: %+v\nSource 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 = ''
164184
}
165185

166186
defer conn.Close()
@@ -180,7 +200,7 @@ func sendLLMNRProbe(ip net.IP) string {
180200
return responderIP
181201
}
182202

183-
// Calculate random hostname by taking random lenght
203+
// Calculate random hostname by taking random length
184204
// of the SHA1 of current time.
185205
func randomHostname() string {
186206
currentTime := time.Now().Format("2006-01-02 15:04:05")
@@ -209,7 +229,7 @@ func getValidIPv4Addr(addrs []net.Addr) net.IP {
209229
func initFlags() {
210230
flag.Usage = func() {
211231
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]")
213233
fmt.Fprintf(os.Stderr, "\n\nFlags:\n")
214234
flag.PrintDefaults()
215235
}

0 commit comments

Comments
 (0)