Skip to content

Commit

Permalink
Added ability to specify interface via flag (Fixes #4).\nA disconnect…
Browse files Browse the repository at this point in the history
…ed/disabled windows interface will now report it and move on to next interface instead of crashing (Fixes #5)
  • Loading branch information
Shivam Patel committed Feb 21, 2018
1 parent 6d505eb commit b1c5bbe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Flags:
the network. Other text is sent to STDERR
-debug
Creates a debug.log file with a trace of the program
-interface string
Interface where responder will be searched (eg. eth0).
Not specifying this flag will search on all interfaces.
-hostname string
Hostname to search for (default "aweirdcomputername")
-rhostname
Expand Down
42 changes: 31 additions & 11 deletions respounder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
'-'
`

Version = 1.1
Version = 1.2
TimeoutSec = 3
BcastAddr = "224.0.0.252"
LLMNRPort = 5355
Expand All @@ -47,18 +47,23 @@ var (

// argument flags
jsonPtr = flag.Bool("json", false,
`Prints a JSON to STDOUT if a responder is detected on
the network. Other text is sent to STDERR`)
`Prints a JSON to STDOUT if a responder is detected in the subnet.
Other text is sent to STDERR`)

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

hostnamePtr = flag.String("hostname", DefaultHostname,
`Hostname to search for`)

randHostnamePtr = flag.Bool("rhostname", false,
`Searches for a hostname comprised of random string instead
of the default hostname ("`+DefaultHostname+`")`)

interfacePtr = flag.String("interface", "",
`Interface where responder will be searched (eg. eth0).
Not specifying this flag will search on all interfaces.`)

hostnameType byte
)

Expand All @@ -70,7 +75,7 @@ func main() {
initFlags()
flag.Parse()

if *hostnamePtr != "aweirdcomputername" {
if *hostnamePtr != DefaultHostname {
hostnameType = newHostname
} else if *randHostnamePtr {
hostnameType = randHostname
Expand All @@ -86,11 +91,27 @@ func main() {

var resultMap []map[string]string

for _, inf := range interfaces {
detailsMap := checkResponderOnInterface(inf)
// send probe on specific interface if -interface flag is set
if *interfacePtr != "" {
inf, err := net.InterfaceByName(*interfacePtr)
if err != nil {
fmt.Printf("Invalid interface '%s'. List of valid interfaces are:\n", *interfacePtr)
for _, inf := range interfaces {
fmt.Println("- " + inf.Name)
}
return
}
detailsMap := checkResponderOnInterface(*inf)
if len(detailsMap) > 0 {
resultMap = append(resultMap, detailsMap)
}
} else { // send probes from all interfaces if -interface flag isn't set
for _, inf := range interfaces {
detailsMap := checkResponderOnInterface(inf)
if len(detailsMap) > 0 {
resultMap = append(resultMap, detailsMap)
}
}
}

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

conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: ip})
if err != nil {
fmt.Println("Couldn't bind to a UDP interface. Bailing out!")
fmt.Printf("Could not bind to the interface. Is it disabled? ")
logger.Printf("Bind error: %+v\nSource IP: %v\n", err, ip)
fmt.Println(err)
logger.Printf("LLMNR request payload was: %x\n", llmnrRequest)
return responderIP // return with IP = ''
}

defer conn.Close()
Expand All @@ -180,7 +200,7 @@ func sendLLMNRProbe(ip net.IP) string {
return responderIP
}

// Calculate random hostname by taking random lenght
// Calculate random hostname by taking random length
// of the SHA1 of current time.
func randomHostname() string {
currentTime := time.Now().Format("2006-01-02 15:04:05")
Expand Down Expand Up @@ -209,7 +229,7 @@ func getValidIPv4Addr(addrs []net.Addr) net.IP {
func initFlags() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Respounder version %1.1f\n", Version)
fmt.Fprintf(os.Stderr, "Usage: $ respounder [-json] [-debug] [-hostname testhostname | -rhostname]")
fmt.Fprintf(os.Stderr, "Usage: $ respounder [-json] [-debug] [-interface <iface>] [-hostname <name> | -rhostname]")
fmt.Fprintf(os.Stderr, "\n\nFlags:\n")
flag.PrintDefaults()
}
Expand Down

0 comments on commit b1c5bbe

Please sign in to comment.