-
Notifications
You must be signed in to change notification settings - Fork 158
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
Support range, cidrs in grepip #188
Merged
UmanShahzad
merged 9 commits into
master
from
talhahameed/be-2716-introduce-flag-in-grepip-to-print-subnets-too
Nov 15, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d24cd5
Support range, cidrs in grepip
talhahwahla 6127d8d
refactor regex
talhahwahla 44df13f
rearrage if else
talhahwahla 2c50f1a
refactor if-else statements for readability
talhahwahla 062e677
rm short flag
talhahwahla 8745736
Add comments about regex
talhahwahla aed7f74
rename octet to v4octet
talhahwahla 0fcb393
fix regex, no space around `,` or `-` in range
talhahwahla 16be478
Merge branch 'master' into talhahameed/be-2716-introduce-flag-in-grep…
talhahwahla 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 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 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 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 |
---|---|---|
|
@@ -5,7 +5,39 @@ import "regexp" | |
func init() { | ||
bogonIP4List = GetBogonRange4() | ||
bogonIP6List = GetBogonRange6() | ||
|
||
// IP | ||
ipV4Regex = regexp.MustCompilePOSIX(IPv4RegexPattern) | ||
ipV6Regex = regexp.MustCompilePOSIX(IPv6RegexPattern) | ||
ipRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv6RegexPattern) | ||
|
||
// IP and CIDR | ||
v4IpCidrRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv4CIDRRegexPattern) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment against each grouped code is warranted now |
||
v6IpCidrRegex = regexp.MustCompilePOSIX(IPv6RegexPattern + "|" + IPv6CIDRRegexPattern) | ||
ipCidrRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv6RegexPattern + "|" + IPv4CIDRRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
|
||
// IP and Range | ||
v4IpRangeRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv4RangeRegexPattern) | ||
v6IpRangeRegex = regexp.MustCompilePOSIX(IPv6RegexPattern + "|" + IPv6RangeRegexPattern) | ||
ipRangeRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv6RegexPattern + "|" + IPv4RangeRegexPattern + "|" + IPv6RangeRegexPattern) | ||
|
||
// IP, CIDR and Range | ||
v4IpSubnetRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv4CIDRRegexPattern + "|" + IPv4RangeRegexPattern) | ||
v6IpSubnetRegex = regexp.MustCompilePOSIX(IPv6RegexPattern + "|" + IPv6RangeRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
ipSubnetRegex = regexp.MustCompilePOSIX(IPv4RegexPattern + "|" + IPv6RegexPattern + "|" + IPv4CIDRRegexPattern + "|" + IPv4RangeRegexPattern + "|" + IPv6RangeRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
|
||
// CIDR | ||
v4CidrRegex = regexp.MustCompilePOSIX(IPv4CIDRRegexPattern) | ||
v6CidrRegex = regexp.MustCompilePOSIX(IPv6CIDRRegexPattern) | ||
cidrRegex = regexp.MustCompilePOSIX(IPv4CIDRRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
|
||
// Range | ||
v4RangeRegex = regexp.MustCompilePOSIX(IPv4RangeRegexPattern) | ||
v6RangeRegex = regexp.MustCompilePOSIX(IPv6RangeRegexPattern) | ||
rangeRegex = regexp.MustCompilePOSIX(IPv4RangeRegexPattern + "|" + IPv6RangeRegexPattern) | ||
|
||
// CIDR and Range | ||
v4SubnetRegex = regexp.MustCompilePOSIX(IPv4RangeRegexPattern + "|" + IPv4CIDRRegexPattern) | ||
v6SubnetRegex = regexp.MustCompilePOSIX(IPv6RangeRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
subnetRegex = regexp.MustCompilePOSIX(IPv4RangeRegexPattern + "|" + IPv4CIDRRegexPattern + "|" + IPv6RangeRegexPattern + "|" + IPv6CIDRRegexPattern) | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the new regexes below add any significant startup time to the command? With so many regexes compiled at startup, wanna make sure the command still runs super fast without overheads, as these regexes would be getting compiled for every single invocation of the CLI no matter what command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execution time has increased now, difference in practice doesn't appear to be as significant, I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went up 13ms, so should be fine for now. We can optimize if it gets worse