-
Notifications
You must be signed in to change notification settings - Fork 95
(feat) Enhance device discovery for complex and mesh networks #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
postphotos
wants to merge
4
commits into
vishen:master
Choose a base branch
from
postphotos:fix/scanning-subnet-bug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
faf10eb
fixed scanner, added localip command and a few other ip utils
postphotos b48f95c
Adding tests for new utils/scan work
postphotos 6bfbdbc
final cleanup of implementation; completing basic documentation of ne…
postphotos 2b35844
Moving broad-search to root.go; removing redundant references throughout
postphotos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var localIPCmd = &cobra.Command{ | ||
| Use: "localip", | ||
| Short: "Print the local IP address used by go-chromecast", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| ifaceName, _ := cmd.Flags().GetString("iface") | ||
| ip, err := detectLocalIP(ifaceName) | ||
| if err != nil { | ||
| exit("unable to determine local IP: %v", err) | ||
| } | ||
| fmt.Println(ip) | ||
| }, | ||
| } | ||
|
|
||
| // detectLocalIP attempts to detect the local IP address based on the network interface | ||
| func detectLocalIP(ifaceName string) (string, error) { | ||
| var iface *net.Interface | ||
| var err error | ||
|
|
||
| if ifaceName != "" { | ||
| iface, err = net.InterfaceByName(ifaceName) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| } | ||
|
|
||
| if iface != nil { | ||
| // Use the specified interface | ||
| addrs, err := iface.Addrs() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| for _, addr := range addrs { | ||
| if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { | ||
| if ipnet.IP.To4() != nil { | ||
| return ipnet.IP.String(), nil | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| // Try to find the default route interface | ||
| interfaces, err := net.Interfaces() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| for _, iface := range interfaces { | ||
| if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 { | ||
| continue | ||
| } | ||
|
|
||
| addrs, err := iface.Addrs() | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| for _, addr := range addrs { | ||
| if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { | ||
| if ipnet.IP.To4() != nil { | ||
| return ipnet.IP.String(), nil | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return "", fmt.Errorf("could not detect local IP address") | ||
| } | ||
|
|
||
| func init() { | ||
| localIPCmd.Flags().String("iface", "", "network interface to use for detecting local IP (optional)") | ||
| rootCmd.AddCommand(localIPCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.