From a5d35d752a1583f0d7a250db96699816534b6d38 Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Mon, 4 Dec 2023 14:43:01 +0500 Subject: [PATCH 01/10] ipinfo-manpage --- debian/files | 1 - debian/rules | 2 +- ipinfo/cmd_default.go | 215 ++++++++++++++++++++++++++++++------------ ipinfo/ipinfo.1 | 210 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 364 insertions(+), 64 deletions(-) delete mode 100644 debian/files create mode 100644 ipinfo/ipinfo.1 diff --git a/debian/files b/debian/files deleted file mode 100644 index 63f4245e..00000000 --- a/debian/files +++ /dev/null @@ -1 +0,0 @@ -ipinfo_3.2.0_source.buildinfo utils optional diff --git a/debian/rules b/debian/rules index 6d3a03c1..2bc43240 100755 --- a/debian/rules +++ b/debian/rules @@ -1,3 +1,3 @@ #!/usr/bin/make -f %: - PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang + PATH=${PATH}:/usr/local/go/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index ddb0de10..cbd7dbb6 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -1,10 +1,13 @@ package main import ( + _ "embed" "errors" "fmt" "net" "os" + "strings" + "unicode" "github.com/fatih/color" "github.com/ipinfo/cli/lib" @@ -12,71 +15,159 @@ import ( "github.com/spf13/pflag" ) +//go:embed ipinfo.1 +var manPage string + +func extractSection(content, sectionStart, sectionEnd string) string { + startIndex := strings.Index(content, sectionStart) + if startIndex == -1 { + return "" + } + + startIndex += len(sectionStart) // exclude the starting substring + endIndex := strings.Index(content[startIndex:], sectionEnd) + if endIndex == -1 { + return "" + } + + return content[startIndex : startIndex+endIndex] +} + +func parseCommandsAndOptions(content string) (commands, options string) { + commands = extractSection(content, ".SH COMMANDS", ".SH") + options = extractSection(content, ".SH OPTIONS", ".SH") + + return commands, options +} + +func formatCommandsAndOptions(commands, options string) string { + var output strings.Builder + output.WriteString(fmt.Sprintf("Usage: %s [] []\n\n", progBase)) + + //Format Commands section + output.WriteString("\nCommands:\n") + + commandLines := strings.Split(commands, ".TP") + for _, comm := range commandLines[1:] { + lines := strings.Split(strings.TrimSpace(comm), "\n") + command := strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")) + description := strings.TrimSpace(lines[1]) + output.WriteString(fmt.Sprintf(" %-10s %s\n", command, description)) + + } + + // Format Options section + output.WriteString("\nOptions:\n") + + optionLines := strings.Split(options, ".TP") + for index, opt := range optionLines[1:] { + lines := strings.Split(strings.TrimSpace(opt), "\n") + + //This means that the current "lines" slice only contains the Sub-Heading. + if len(lines) == 1 { + subHeading := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")), " OPTIONS:")) + + //To convert Subheadings of Options sections (GENERAL, OUTPUT, FORMAT) to (General, Output, Format). + subHeadingRunes := []rune(subHeading) + subHeadingRunes[0] = unicode.ToUpper(subHeadingRunes[0]) + subHeading = string(subHeadingRunes) + + //To determine when to put a newline before a Subheading + if index == 0 { + output.WriteString(fmt.Sprintf(" %s:\n", subHeading)) + } else { + output.WriteString(fmt.Sprintf("\n %s:\n", subHeading)) + } + + // This means that the current "lines" slice contains the option and its description. + } else { + option := strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")) + description := strings.TrimSpace(lines[1]) + + //To skip printing a newline after the last option/description pair in the loop + if index == len(optionLines)-2 { + output.WriteString(fmt.Sprintf(" %s\n %s", option, description)) + } else { + output.WriteString(fmt.Sprintf(" %s\n %s\n", option, description)) + } + + } + } + + return output.String() +} + func printHelpDefault() { - fmt.Printf( - `Usage: %s [] [] - -Commands: - look up details for an IP address, e.g. 8.8.8.8. - look up details for an ASN, e.g. AS123 or as123. - myip get details for your IP. - bulk get details for multiple IPs in bulk. - asn tools related to ASNs. - summarize get summarized data for a group of IPs. - map open a URL to a map showing the locations of a group of IPs. - prips print IP list from CIDR or range. - grepip grep for IPs matching criteria from any source. - matchip print the overlapping IPs and subnets. - grepdomain grep for domains matching criteria from any source. - cidr2range convert CIDRs to IP ranges. - cidr2ip convert CIDRs to individual IPs within those CIDRs. - range2cidr convert IP ranges to CIDRs. - range2ip convert IP ranges to individual IPs within those ranges. - randip Generates random IPs. - splitcidr splits a larger CIDR into smaller CIDRs. - mmdb read, import and export mmdb files. - calc evaluates a mathematical expression that may contain IP addresses. - tool misc. tools related to IPs, IP ranges and CIDRs. - download download free ipinfo database files. - cache manage the cache. - config manage the config. - quota print the request quota of your account. - init login or signup account. - logout delete your current API token session. - completion install or output shell auto-completion script. - version show current version. - -Options: - General: - --token , -t - use as API token. - --nocache - do not use the cache. - --version, -v - show binary release number. - --help, -h - show help. - - Outputs: - --field , -f - lookup only specific fields in the output. - field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. - multiple field names must be separated by commas. - --nocolor - disable colored output. - - Formats: - --pretty, -p - output pretty format. - --json, -j - output JSON format. - --csv, -c - output CSV format. - --yaml, -y - output YAML format. -`, progBase) + commands, options := parseCommandsAndOptions(manPage) + formattedOutput := formatCommandsAndOptions(commands, options) + fmt.Println(formattedOutput) } +// func printHelpDefault() { +// fmt.Printf( +// `Usage: %s [] [] + +// Commands: +// look up details for an IP address, e.g. 8.8.8.8. +// look up details for an ASN, e.g. AS123 or as123. +// myip get details for your IP. +// bulk get details for multiple IPs in bulk. +// asn tools related to ASNs. +// summarize get summarized data for a group of IPs. +// map open a URL to a map showing the locations of a group of IPs. +// prips print IP list from CIDR or range. +// grepip grep for IPs matching criteria from any source. +// matchip print the overlapping IPs and subnets. +// grepdomain grep for domains matching criteria from any source. +// cidr2range convert CIDRs to IP ranges. +// cidr2ip convert CIDRs to individual IPs within those CIDRs. +// range2cidr convert IP ranges to CIDRs. +// range2ip convert IP ranges to individual IPs within those ranges. +// randip Generates random IPs. +// splitcidr splits a larger CIDR into smaller CIDRs. +// mmdb read, import and export mmdb files. +// calc evaluates a mathematical expression that may contain IP addresses. +// tool misc. tools related to IPs, IP ranges and CIDRs. +// download download free ipinfo database files. +// cache manage the cache. +// config manage the config. +// quota print the request quota of your account. +// init login or signup account. +// logout delete your current API token session. +// completion install or output shell auto-completion script. +// version show current version. + +// Options: +// General: +// --token , -t +// use as API token. +// --nocache +// do not use the cache. +// --version, -v +// show binary release number. +// --help, -h +// show help. + +// Outputs: +// --field , -f +// lookup only specific fields in the output. +// field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. +// multiple field names must be separated by commas. +// --nocolor +// disable colored output. + +// Formats: +// --pretty, -p +// output pretty format. +// --json, -j +// output JSON format. +// --csv, -c +// output CSV format. +// --yaml, -y +// output YAML format. +// `, progBase) +// } + func cmdDefault() (err error) { var ips []net.IP var fTok string diff --git a/ipinfo/ipinfo.1 b/ipinfo/ipinfo.1 new file mode 100644 index 00000000..258f4a1a --- /dev/null +++ b/ipinfo/ipinfo.1 @@ -0,0 +1,210 @@ +.TH ipinfo 1 "November 2023" "ipinfo" + +.SH NAME +ipinfo \- IP information lookup tool + +.SH SYNOPSIS +.B ipinfo +[\fICOMMAND\fP] [\fIOPTIONS\fP] [\fIARGUMENTS\fP] + +.SH DESCRIPTION +The +.B ipinfo +command is a versatile tool for retrieving information related to IP addresses, Autonomous System Numbers (ASNs), and various related operations. It provides detailed insights into IP addresses, ASN details, and offers a range of utilities for managing and analyzing IP-related information. + +When invoked without any command or options, it provides a summary. + +.SH COMMANDS +.TP +.B +Look up details for an IP address, e.g. 8.8.8.8. + +.TP +.B +Look up details for an ASN, e.g. AS123 or as123. + +.TP +.B myip +Get details for your IP. + +.TP +.B bulk +Get details for multiple IPs in bulk. + +.TP +.B asn +Tools related to ASNs. + +.TP +.B summarize +Get summarized data for a group of IPs. + +.TP +.B map +Open a URL to a map showing the locations of a group of IPs. + +.TP +.B prips +Print IP list from CIDR or range. + +.TP +.B grepip +Grep for IPs matching criteria from any source. + +.TP +.B matchip +Print the overlapping IPs and subnets. + +.TP +.B grepdomain +Grep for domains matching criteria from any source. + +.TP +.B cidr2range +Convert CIDRs to IP ranges. + +.TP +.B cidr2ip +Convert CIDRs to individual IPs within those CIDRs. + +.TP +.B range2cidr +Convert IP ranges to CIDRs. + +.TP +.B range2ip +Convert IP ranges to individual IPs within those ranges. + +.TP +.B randip +Generates random IPs. + +.TP +.B splitcidr +Splits a larger CIDR into smaller CIDRs. + +.TP +.B mmdb +Read, import, and export mmdb files. + +.TP +.B calc +Evaluates a mathematical expression that may contain IP addresses. + +.TP +.B tool +Misc. tools related to IPs, IP ranges, and CIDRs. + +.TP +.B download +Download free ipinfo database files. + +.TP +.B cache +Manage the cache. + +.TP +.B config +Manage the config. + +.TP +.B quota +Print the request quota of your account. + +.TP +.B init +Login or signup account. + +.TP +.B logout +Delete your current API token session. + +.TP +.B completion +Install or output shell auto-completion script. + +.TP +.B version +Show current version. + +.SH OPTIONS + +.TP +.B GENERAL OPTIONS: + + +.TP +.B --token , -t +Use as API token. + +.TP +.B --nocache +Do not use the cache. + +.TP +.B --version, -v +Show binary release number. + +.TP +.B --help, -h +Show help. + + +.TP +.B OUTPUT OPTIONS: + + +.TP +.B --field , -f +Lookup only specific fields in the output. +Field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. +Multiple field names must be separated by commas. + +.TP +.B --nocolor +Disable colored output. + + +.TP +.B FORMAT OPTIONS: + + +.TP +.B --pretty, -p +Output pretty format. + +.TP +.B --json, -j +Output JSON format. + +.TP +.B --csv, -c +Output CSV format. + +.TP +.B --yaml, -y +Output YAML format. + +.SH EXAMPLES +.TP +.B ipinfo myip +Get details for your IP. + +.TP +.B ipinfo 8.8.8.8 +Look up details for a specific ip address. + +.TP +.B ipinfo +Get a summary regarding the command. + +.TP +.B ipinfo grepdomain -n file.txt +Access subcommands through the main command. + +.SH SEE ALSO +.BR ipinfo-asn (1), +.BR ipinfo-bulk (1). + +.SH REPORTING BUGS +Report bugs to: https://github.com/ipinfo/cli/issues From f4a8f873fc5bd45a8c050a01698ceaad24bfc108 Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Thu, 7 Dec 2023 12:33:26 +0500 Subject: [PATCH 02/10] Handled man page installation --- debian/files | 1 + debian/ipinfo.manpages | 1 + debian/rules | 16 +++++++++++++++- ipinfo/cmd_default.go | 2 +- scripts/build-archive-all.sh | 6 ++++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 debian/files create mode 100644 debian/ipinfo.manpages diff --git a/debian/files b/debian/files new file mode 100644 index 00000000..3a3805e5 --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +ipinfo_3.2.0_source.buildinfo utils optional \ No newline at end of file diff --git a/debian/ipinfo.manpages b/debian/ipinfo.manpages new file mode 100644 index 00000000..7bf57ed1 --- /dev/null +++ b/debian/ipinfo.manpages @@ -0,0 +1 @@ +ipinfo/ipinfo.1 \ No newline at end of file diff --git a/debian/rules b/debian/rules index 2bc43240..1ccca4df 100755 --- a/debian/rules +++ b/debian/rules @@ -1,3 +1,17 @@ #!/usr/bin/make -f %: - PATH=${PATH}:/usr/local/go/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang + PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang + + +override_dh_auto_build: + cp ipinfo/ipinfo.1 _build/src/github.com/ipinfo/cli/ipinfo + dh_auto_build + + + +override_dh_auto_install: + dh_auto_install + + dh_installman + + diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index cbd7dbb6..fd0fb94f 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -67,7 +67,7 @@ func formatCommandsAndOptions(commands, options string) string { if len(lines) == 1 { subHeading := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")), " OPTIONS:")) - //To convert Subheadings of Options sections (GENERAL, OUTPUT, FORMAT) to (General, Output, Format). + //To convert Subheadings of Options section (GENERAL, OUTPUT, FORMAT) to (General, Output, Format). subHeadingRunes := []rune(subHeading) subHeadingRunes[0] = unicode.ToUpper(subHeadingRunes[0]) subHeading = string(subHeadingRunes) diff --git a/scripts/build-archive-all.sh b/scripts/build-archive-all.sh index f2ecc970..a3568925 100755 --- a/scripts/build-archive-all.sh +++ b/scripts/build-archive-all.sh @@ -10,6 +10,7 @@ ROOT=$DIR/.. CLI=$1 VSN=$2 + if [ -z "$CLI" ]; then echo "require cli as first parameter" 2>&1 exit 1 @@ -44,4 +45,9 @@ cd .. rm -rf $ROOT/${CLI}/dist/usr mkdir -p $ROOT/${CLI}/dist/usr/local/bin cp $ROOT/build/${CLI}_${VSN}_linux_amd64 $ROOT/${CLI}/dist/usr/local/bin/${CLI} + +# Copy man page to the appropriate location +mkdir -p $ROOT/${CLI}/dist/usr/share/man/man1 +cp $ROOT/ipinfo/ipinfo.1 $ROOT/${CLI}/dist/usr/share/man/man1/ + dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb From 4c5efbcd79255ff98d42d913fcafda9e76e99eef Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Mon, 11 Dec 2023 16:46:12 +0500 Subject: [PATCH 03/10] revision: --help opens a pager using less --- debian/files | 2 +- debian/ipinfo.manpages | 1 - debian/rules | 16 +- ipinfo/cmd_default.go | 228 +++---- ipinfo/detailed_help.go | 1220 ++++++++++++++++++++++++++++++++++ ipinfo/ipinfo.1 | 210 ------ ipinfo/main.go | 1 + scripts/build-archive-all.sh | 8 +- 8 files changed, 1305 insertions(+), 381 deletions(-) delete mode 100644 debian/ipinfo.manpages create mode 100644 ipinfo/detailed_help.go delete mode 100644 ipinfo/ipinfo.1 diff --git a/debian/files b/debian/files index 3a3805e5..63f4245e 100644 --- a/debian/files +++ b/debian/files @@ -1 +1 @@ -ipinfo_3.2.0_source.buildinfo utils optional \ No newline at end of file +ipinfo_3.2.0_source.buildinfo utils optional diff --git a/debian/ipinfo.manpages b/debian/ipinfo.manpages deleted file mode 100644 index 7bf57ed1..00000000 --- a/debian/ipinfo.manpages +++ /dev/null @@ -1 +0,0 @@ -ipinfo/ipinfo.1 \ No newline at end of file diff --git a/debian/rules b/debian/rules index 1ccca4df..b6f61f4f 100755 --- a/debian/rules +++ b/debian/rules @@ -1,17 +1,3 @@ #!/usr/bin/make -f %: - PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang - - -override_dh_auto_build: - cp ipinfo/ipinfo.1 _build/src/github.com/ipinfo/cli/ipinfo - dh_auto_build - - - -override_dh_auto_install: - dh_auto_install - - dh_installman - - + PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang \ No newline at end of file diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index fd0fb94f..2074acc5 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -4,10 +4,11 @@ import ( _ "embed" "errors" "fmt" + "io" "net" "os" + "os/exec" "strings" - "unicode" "github.com/fatih/color" "github.com/ipinfo/cli/lib" @@ -15,159 +16,85 @@ import ( "github.com/spf13/pflag" ) -//go:embed ipinfo.1 -var manPage string - -func extractSection(content, sectionStart, sectionEnd string) string { - startIndex := strings.Index(content, sectionStart) - if startIndex == -1 { - return "" - } - - startIndex += len(sectionStart) // exclude the starting substring - endIndex := strings.Index(content[startIndex:], sectionEnd) - if endIndex == -1 { - return "" - } - - return content[startIndex : startIndex+endIndex] -} - -func parseCommandsAndOptions(content string) (commands, options string) { - commands = extractSection(content, ".SH COMMANDS", ".SH") - options = extractSection(content, ".SH OPTIONS", ".SH") - - return commands, options +func printHelpDefault() { + fmt.Printf( + `Usage: %s [] [] + +Commands: + look up details for an IP address, e.g. 8.8.8.8. + look up details for an ASN, e.g. AS123 or as123. + myip get details for your IP. + bulk get details for multiple IPs in bulk. + asn tools related to ASNs. + summarize get summarized data for a group of IPs. + map open a URL to a map showing the locations of a group of IPs. + prips print IP list from CIDR or range. + grepip grep for IPs matching criteria from any source. + matchip print the overlapping IPs and subnets. + grepdomain grep for domains matching criteria from any source. + cidr2range convert CIDRs to IP ranges. + cidr2ip convert CIDRs to individual IPs within those CIDRs. + range2cidr convert IP ranges to CIDRs. + range2ip convert IP ranges to individual IPs within those ranges. + randip Generates random IPs. + splitcidr splits a larger CIDR into smaller CIDRs. + mmdb read, import and export mmdb files. + calc evaluates a mathematical expression that may contain IP addresses. + tool misc. tools related to IPs, IP ranges and CIDRs. + download download free ipinfo database files. + cache manage the cache. + config manage the config. + quota print the request quota of your account. + init login or signup account. + logout delete your current API token session. + completion install or output shell auto-completion script. + version show current version. + +Options: + General: + --token , -t + use as API token. + --nocache + do not use the cache. + --version, -v + show binary release number. + --help, -h + show help. + + Outputs: + --field , -f + lookup only specific fields in the output. + field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. + multiple field names must be separated by commas. + --nocolor + disable colored output. + + Formats: + --pretty, -p + output pretty format. + --json, -j + output JSON format. + --csv, -c + output CSV format. + --yaml, -y + output YAML format. +`, progBase) } -func formatCommandsAndOptions(commands, options string) string { - var output strings.Builder - output.WriteString(fmt.Sprintf("Usage: %s [] []\n\n", progBase)) +func pageHelp(detailedHelp string) error { - //Format Commands section - output.WriteString("\nCommands:\n") + cmd := exec.Command("less") - commandLines := strings.Split(commands, ".TP") - for _, comm := range commandLines[1:] { - lines := strings.Split(strings.TrimSpace(comm), "\n") - command := strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")) - description := strings.TrimSpace(lines[1]) - output.WriteString(fmt.Sprintf(" %-10s %s\n", command, description)) + // Create an io.Reader from the detailed help string + reader := io.Reader(strings.NewReader(detailedHelp)) + cmd.Stdin = reader - } + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr - // Format Options section - output.WriteString("\nOptions:\n") - - optionLines := strings.Split(options, ".TP") - for index, opt := range optionLines[1:] { - lines := strings.Split(strings.TrimSpace(opt), "\n") - - //This means that the current "lines" slice only contains the Sub-Heading. - if len(lines) == 1 { - subHeading := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")), " OPTIONS:")) - - //To convert Subheadings of Options section (GENERAL, OUTPUT, FORMAT) to (General, Output, Format). - subHeadingRunes := []rune(subHeading) - subHeadingRunes[0] = unicode.ToUpper(subHeadingRunes[0]) - subHeading = string(subHeadingRunes) - - //To determine when to put a newline before a Subheading - if index == 0 { - output.WriteString(fmt.Sprintf(" %s:\n", subHeading)) - } else { - output.WriteString(fmt.Sprintf("\n %s:\n", subHeading)) - } - - // This means that the current "lines" slice contains the option and its description. - } else { - option := strings.TrimSpace(strings.TrimPrefix(lines[0], ".B")) - description := strings.TrimSpace(lines[1]) - - //To skip printing a newline after the last option/description pair in the loop - if index == len(optionLines)-2 { - output.WriteString(fmt.Sprintf(" %s\n %s", option, description)) - } else { - output.WriteString(fmt.Sprintf(" %s\n %s\n", option, description)) - } - - } - } - - return output.String() -} - -func printHelpDefault() { - commands, options := parseCommandsAndOptions(manPage) - formattedOutput := formatCommandsAndOptions(commands, options) - fmt.Println(formattedOutput) + return cmd.Run() } -// func printHelpDefault() { -// fmt.Printf( -// `Usage: %s [] [] - -// Commands: -// look up details for an IP address, e.g. 8.8.8.8. -// look up details for an ASN, e.g. AS123 or as123. -// myip get details for your IP. -// bulk get details for multiple IPs in bulk. -// asn tools related to ASNs. -// summarize get summarized data for a group of IPs. -// map open a URL to a map showing the locations of a group of IPs. -// prips print IP list from CIDR or range. -// grepip grep for IPs matching criteria from any source. -// matchip print the overlapping IPs and subnets. -// grepdomain grep for domains matching criteria from any source. -// cidr2range convert CIDRs to IP ranges. -// cidr2ip convert CIDRs to individual IPs within those CIDRs. -// range2cidr convert IP ranges to CIDRs. -// range2ip convert IP ranges to individual IPs within those ranges. -// randip Generates random IPs. -// splitcidr splits a larger CIDR into smaller CIDRs. -// mmdb read, import and export mmdb files. -// calc evaluates a mathematical expression that may contain IP addresses. -// tool misc. tools related to IPs, IP ranges and CIDRs. -// download download free ipinfo database files. -// cache manage the cache. -// config manage the config. -// quota print the request quota of your account. -// init login or signup account. -// logout delete your current API token session. -// completion install or output shell auto-completion script. -// version show current version. - -// Options: -// General: -// --token , -t -// use as API token. -// --nocache -// do not use the cache. -// --version, -v -// show binary release number. -// --help, -h -// show help. - -// Outputs: -// --field , -f -// lookup only specific fields in the output. -// field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. -// multiple field names must be separated by commas. -// --nocolor -// disable colored output. - -// Formats: -// --pretty, -p -// output pretty format. -// --json, -j -// output JSON format. -// --csv, -c -// output CSV format. -// --yaml, -y -// output YAML format. -// `, progBase) -// } - func cmdDefault() (err error) { var ips []net.IP var fTok string @@ -181,7 +108,8 @@ func cmdDefault() (err error) { pflag.StringVarP(&fTok, "token", "t", "", "the token to use.") pflag.BoolVar(&fNoCache, "nocache", false, "disable the cache.") pflag.BoolVarP(&fVsn, "version", "v", false, "print binary release number.") - pflag.BoolVarP(&fHelp, "help", "h", false, "show help.") + pflag.BoolVarP(&fHelp, "short-help", "h", false, "show help.") + pflag.BoolVar(&fLess, "help", false, "use less for detailed help") pflag.StringSliceVarP(&fField, "field", "f", nil, "specific field to lookup.") pflag.BoolVarP(&fPretty, "pretty", "p", true, "output pretty format.") pflag.BoolVarP(&fJSON, "json", "j", true, "output JSON format. (default)") @@ -199,6 +127,12 @@ func cmdDefault() (err error) { return nil } + if fLess { + // Read the contents of the help file and pipe to less + err = pageHelp(DetailedHelp) + return err + } + if fVsn { fmt.Println(version) return nil diff --git a/ipinfo/detailed_help.go b/ipinfo/detailed_help.go new file mode 100644 index 00000000..cdd3116c --- /dev/null +++ b/ipinfo/detailed_help.go @@ -0,0 +1,1220 @@ +package main + +var DetailedHelp = `ipinfo - IP information lookup tool. + +Usage: + ipinfo [options] [arguments] + +Commands: + ipinfo Lookup details for a specific IP address. + Options: + --field , -f + Lookup only specific fields in the output. + --nocolor + Disable colored output. + --json, -j + Output JSON format. + --csv, -c + Output CSV format. + --yaml, -y + Output YAML format. + + Examples: + ipinfo 8.8.8.8 + ipinfo 8.8.8.8 --field hostname,city + + + ipinfo Lookup details for a specific ASN. + Options: + --field + Lookup only specific fields in the output. + --nocolor + Disable colored output. + --json, -j + Output JSON format. + --csv, -c + Output CSV format. + --yaml, -y + Output YAML format. + + Examples: + ipinfo + ipinfo --field hostname,city + + + ipinfo myip Get details for your IP. + Usage: + ipinfo myip [] + + Options: + --field + Lookup only specific fields in the output. + --nocolor + Disable colored output. + --json, -j + Output JSON format. + --csv, -c + Output CSV format. + --yaml, -y + Output YAML format. + + Examples: + ipinfo myip + ipinfo myip --field hostname,city + + + ipinfo bulk Get details for multiple IPs in bulk. + Usage: + ipinfo bulk [] + + Options: + --field Lookup only specific fields in the output. + --json, -j Output JSON format. + --csv, -c Output CSV format. + --yaml, -y Output YAML format. + + Examples: + # Lookup all IPs from stdin ('-' can be implied). + $ ipinfo prips 8.8.8.0/24 | ipinfo bulk + $ ipinfo prips 8.8.8.0/24 | ipinfo bulk - + + # Lookup all IPs in 2 files. + $ ipinfo bulk /path/to/iplist1.txt /path/to/iplist2.txt + + # Lookup all IPs from CIDR. + $ ipinfo bulk 8.8.8.0/24 + + # Lookup all IPs from multiple CIDRs. + $ ipinfo bulk 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 + + # Lookup all IPs in an IP range. + $ ipinfo bulk 8.8.8.0-8.8.8.255 + + # Lookup all IPs from multiple sources simultaneously. + $ ipinfo bulk 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt + + + ipinfo asn Tools related to ASNs. + Usage: + ipinfo asn [] + + Commands: + bulk lookup ASNs in bulk + + + ipinfo summarize Get summarized data for a group of IPs. + Usage: + ipinfo summarize [] + + Options: + --json, -j + Output JSON format. + --csv, -c + Output CSV format. + --yaml, -y + Output YAML format. + + Examples: + # Summarize all IPs from stdin ('-' can be implied). + $ ipinfo prips 8.8.8.0/24 | ipinfo summarize + $ ipinfo prips 8.8.8.0/24 | ipinfo summarize - + + # Summarize all IPs in 2 files. + $ ipinfo summarize /path/to/iplist1.txt /path/to/iplist2.txt + + # Summarize all IPs from CIDR. + $ ipinfo summarize 8.8.8.0/24 + + # Summarize all IPs from multiple CIDRs. + $ ipinfo summarize 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 + + # Summarize all IPs in an IP range. + $ ipinfo summarize 8.8.8.0-8.8.8.255 + + # Summarize all IPs from multiple sources simultaneously. + $ ipinfo summarize 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt + + + ipinfo map Open a URL to a map showing the locations of a group of IPs. + Usage: + ipinfo map [] + + Options: + --no-browser + don't open the map link in the browser + default is false. + + Examples: + # Map all IPs from stdin ('-' can be implied). + $ ipinfo prips 8.8.8.0/24 | ipinfo map + $ ipinfo prips 8.8.8.0/24 | ipinfo map - + + # Map all IPs in 2 files. + $ ipinfo map /path/to/iplist1.txt /path/to/iplist2.txt + + # Map all IPs from CIDR. + $ ipinfo map 8.8.8.0/24 + + # Map all IPs from multiple CIDRs. + $ ipinfo map 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 + + # Map all IPs in an IP range. + $ ipinfo map 8.8.8.0-8.8.8.255 + + # Map all IPs from multiple sources simultaneously. + $ ipinfo map 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt + + + ipinfo prips Print IP list from CIDR or range. + Usage: + ipinfo prips [] + + Examples: + # List all IPs in a CIDR. + $ ipinfo prips 8.8.8.0/24 + + # List all IPs in multiple CIDRs. + $ ipinfo prips 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 + + # List all IPs in an IP range. + $ ipinfo prips 8.8.8.0-8.8.8.255 + + # List all IPs in multiple CIDRs and IP ranges. + $ ipinfo prips 1.1.1.0/30 8.8.8.0-8.8.8.255 2.2.2.0/30 7.7.7.0,7.7.7.10 + + # List all IPs from stdin input (newline-separated). + $ echo '1.1.1.0/30\n8.8.8.0-8.8.8.255\n7.7.7.0,7.7.7.10' | ipinfo prips + + + ipinfo grepip Grep for IPs matching criteria from any source. + Usage: + ipinfo grepip [] + + Options: + --only-matching, -o + print only matched IP in result line, excluding surrounding content. + --no-filename, -h + don't print source of match in result lines when more than 1 source. + --no-recurse + don't recurse into more directories in directory sources. + + Filters: + --ipv4, -4 + match only IPv4 addresses. + --ipv6, -6 + match only IPv6 addresses. + --exclude-reserved, -x + exclude reserved/bogon IPs. + full list can be found at https://ipinfo.io/bogon. + + Examples: + ipinfo grepip -o + + + ipinfo matchip Print the overlapping IPs and subnets. + Usage: + ipinfo matchip [flags] + + Flags: + --expression, -e CIDRs, ip-ranges to to check overlap with. Can be used multiple times. + + Examples: + # Single expression + single file + $ ipinfo matchip 127.0.0.1/24 file1.txt + + # Single expression + multiple files + $ ipinfo matchip 127.0.0.1/24 file1.txt file2.txt file3.txt + + # Multi-expression + any files + $ cat expression-list1.txt | ipinfo matchip -e 127.0.0.1/24 -e 8.8.8.8-8.8.9.10 -e - -e expression-list2.txt file1.txt file2.txt file3.txt + + # First arg is expression + $ ipinfo matchip 8.8.8.8-8.8.9.10 8.8.0.0/16 8.8.0.10 + + + ipinfo gredomain Grep for domains matching criteria from any source. + Usage: + ipinfo grepdomain [] + + Options: + --only-matching, -o + print only matched IP in result line, excluding surrounding content. + --no-filename, -h + don't print source of match in result lines when more than 1 source. + --no-recurse + don't recurse into more directories in directory sources. + + Filters: + --no-punycode, -n + do not convert domains to punycode. + + Examples: + ipinfo grepdomain -o + + + ipinfo cidr2range Convert CIDRs to IP ranges. + Usage: + ipinfo cidr2range [] + + Examples: + # Get the range for CIDR 1.1.1.0/30. + $ ipinfo cidr2range 1.1.1.0/30 + + # Convert CIDR entries to IP ranges in 2 files. + $ ipinfo cidr2range /path/to/file1.txt /path/to/file2.txt + + # Convert CIDR entries to IP ranges from stdin. + $ cat /path/to/file1.txt | ipinfo cidr2range + + # Convert CIDR entries to IP ranges from stdin and a file. + $ cat /path/to/file1.txt | ipinfo cidr2range /path/to/file2.txt + + + ipinfo cidr2ip Convert CIDRs to individual IPs within those CIDRs. + Usage: + ipinfo cidr2ip [] + + Examples: + ipinfo cidr2ip 8.8.8.0/24 + + + ipinfo range2cidr Convert IP ranges to CIDRs. + Usage: + ipinfo range2cidr [] + + Description: + Accepts IP ranges and file paths to files containing IP ranges, converting + them all to CIDRs (and multiple CIDRs if required). + + If a file is input, it is assumed that the IP range to convert is the first + entry of each line. Other data is allowed and copied transparently. + + If multiple CIDRs are needed to represent an IP range on a line with other + data, the data is copied per CIDR required. For example: + + in[0]: "1.1.1.0,1.1.1.2,other-data" + out[0]: "1.1.1.0/31,other-data" + out[1]: "1.1.1.2/32,other-data" + + IP ranges can have the form "" where "" can be "," or + "-", and "" and "" can be any 2 IPs; order does not matter, but + the resulting CIDRs are printed in the order they cover the range. + + Examples: + # Get all CIDRs for range 1.1.1.0-1.1.1.2. + $ ipinfo range2cidr 1.1.1.0-1.1.1.2 + $ ipinfo range2cidr 1.1.1.0,1.1.1.2 + + # Convert all range entries to CIDRs in 2 files. + $ ipinfo range2cidr /path/to/file1.txt /path/to/file2.txt + + # Convert all range entries to CIDRs from stdin. + $ cat /path/to/file1.txt | ipinfo range2cidr + + # Convert all range entries to CIDRs from stdin and a file. + $ cat /path/to/file1.txt | ipinfo range2cidr /path/to/file2.txt + + + ipinfo range2ip Convert IP ranges to individual IPs within those ranges. + Usage: ipinfo range2ip [] + + Description: + Accepts IP ranges and file paths to files containing IP ranges, converting + them all to individual IPs within those ranges. + + $ ipinfo range2ip 8.8.8.0-8.8.8.255 + + IP ranges can be of the form "" where "" can be "," or + "-", and "" and "" can be any 2 IPs; order does not matter. + + + ipinfo randip Generates random IPs. + Usage: + ipinfo randip [] + + Description: + Generate random IPs. + + By default, generates 1 random IPv4 address with starting range 0.0.0.0 and + ending range 255.255.255.255, but can be configured to generate any number of + a combination of IPv4/IPv6 addresses within any range. + + Using --ipv6 or -6 without any starting or ending range will generate a IP + between range of :: to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff. + + Note that only IPv4 or IPv6 IPs can be generated, but not both. + + When generating unique IPs, the range size must not be less than the desired + number of random IPs. + + Options: + --num, -n + number of IPs to generate. + --ipv4, -4 + generate IPv4 IPs. + --ipv6, -6 + generate IPv6 IPs. + --start, -s + starting range of IPs. default: minimum IP possible for IP type selected. + --end, -e + ending range of IPs. default: maximum IP possible for IP type selected. + --exclude-reserved -x + exclude reserved/bogon IPs. full list can be found at https://ipinfo.io/bogon. + --unique, -u + generate unique IPs. + + Examples: + ipinfo randip --count 5 + + + ipinfo splitcidr Splits a larger CIDR into smaller CIDRs. + Usage: + ipinfo splitcidr + + Examples: + ipinfo splitcidr 8.8.8.0/24 25 + + + ipinfo mmdb Read, import, and export mmdb files. + Usage: + ipinfo mmdb [] [] + + Commands: + read read data for IPs in an mmdb file. + Usage: + ipinfo mmdb read [] + + Options: + -f , --format + the output format. + can be "json", "json-compact", "json-pretty", "tsv" or "csv". Note that "json" is short for "json-compact". + default: json. + + import import data in non-mmdb format into mmdb. + Usage: + ipinfo mmdb import [] [] [] + + Options: + Input/Output: + -i , --in + input file name. (e.g. data.csv or - for stdin) + must be in CSV, TSV or JSON. + default: stdin. + -o , --out + output file name. (e.g. sample.mmdb) + default: stdout. + -c, --csv + interpret input file as CSV. + by default, the .csv extension will turn this on. + -t, --tsv + interpret input file as TSV. + by default, the .tsv extension will turn this on. + -j, --json + interpret input file as JSON. + by default, the .json extension will turn this on. + + Fields: + One of the following fields flags, or other flags that implicitly specify + these, must be used, otherwise --fields-from-header is assumed. + + The first field is always implicitly the network field, unless + --range-multicol is used, in which case the first 2 fields are considered + to be start_ip,end_ip. + + When specifying --fields, do not specify the network column(s). + + -f, --fields + explicitly specify the fields to assume exist in the input file. + example: col1,col2,col3 + default: N/A. + --fields-from-header + assume first line of input file is a header, and set the fields as that. + default: true if no other field source is used, false otherwise. + --range-multicol + assume that the network field is actually two columns start_ip,end_ip. + default: false. + --joinkey-col + assume --range-multicol and that the 3rd column is join_key, and ignore + this column when converting to JSON. + default: false. + --no-fields + specify that no fields exist except the implicit network field. + when enabled, --no-network has no effect; the network field is written. + default: false. + --no-network + if --fields-from-header is set, then don't write the network field, which + is assumed to be the *first* field in the header. + default: false. + + Meta: + --ip <4 | 6> + output file's ip version. + default: 6. + -s, --size <24 | 28 | 32> + size of records in the mmdb tree. + default: 32. + -m, --merge + the merge strategy to use when inserting entries that conflict. + none => no merge; only replace conflicts. + toplevel => merge only top-level keys. + recurse => recursively merge. + default: none. + --ignore-empty-values + if enabled, write into /0 with empty values for all fields, and for any + entry, don't write out a field whose value is the empty string. + default: false. + --disallow-reserved + disallow reserved networks to be added to the tree. + default: false. + --alias-6to4 + enable the mapping of some IPv6 networks into the IPv4 network, e.g. + ::ffff:0:0/96, 2001::/32 & 2002::/16. + default: false. + --disable-metadata-pointers + some mmdb readers fail to properly read pointers within metadata. this + allows turning off such pointers. + default: true. + + Example: + # Imports an input file and outputs an mmdb file with default configurations. + $ ipinfo mmdb import input.csv output.mmdb + + + export export data from mmdb format into non-mmdb format. + Usage: + ipinfo mmdb export [] [] + + Options: + Input/Output: + -o , --out + output file name. (e.g. out.csv) + default: if specified, otherwise stdout. + + Format: + -f , --format + the output file format. + can be "csv", "tsv" or "json". + default: csv if output file ends in ".csv", tsv if ".tsv", + json if ".json", otherwise csv. + --no-header + don't output the header for file formats that include one, like + CSV/TSV/JSON. + default: false. + + + diff see the difference between two mmdb files. + Usage: + ipinfo mmdb diff [] + + Description: + Print subnet and record differences between two mmdb files (i.e. do set + difference "(new - old) U (old - new))". + + Options: + --subnets, -s + show subnets difference. + --records, -r + show records difference. + + + metadata print metadata from the mmdb file. + Usage: + ipinfo mmdb metadata [] + + Options: + --nocolor + disable colored output. + + Format: + -f , --format + the metadata output format. + can be "pretty" or "json". + default: pretty. + + + verify check that the mmdb file is not corrupted or invalid. + Usage: + ipinfo mmdb verify [] + + + completion install or output shell auto-completion script. + + + Options: + --nocolor disable colored output. + + + ipinfo calc Evaluates a mathematical expression that may contain IP addresses. + Usage: + ipinfo calc [] + + Examples: + ipinfo calc "2*2828-1" + ipinfo calc "190.87.89.1*2" + ipinfo calc "2001:0db8:85a3:0000:0000:8a2e:0370:7334*6" + + + ipinfo tool Misc. tools related to IPs, IP ranges, and CIDRs. + Usage: + ipinfo tool [] [] + + Commands: + aggregate aggregate IPs, IP ranges, and CIDRs. + Usage: + ipinfo tool aggregate [] + + Description: + Accepts IPv4 IPs and CIDRs, aggregating them efficiently. + + If input contains single IPs, it tries to merge them into the input CIDRs, + otherwise they are printed to the output as they are. + + IP range can be of format , where can either + be a ',' or a '-'. + + + Examples: + # Aggregate two CIDRs. + $ ipinfo tool aggregate 1.1.1.0/30 1.1.1.0/28 + + # Aggregate enteries from 2 files. + $ ipinfo tool aggregate /path/to/file1.txt /path/to/file2.txt + + # Aggregate enteries from stdin. + $ cat /path/to/file1.txt | ipinfo tool aggregate + + # Aggregate enteries from stdin and a file. + $ cat /path/to/file1.txt | ipinfo tool aggregate /path/to/file2.txt + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + next get the next IP of the input IP + Usage: + ipinfo tool next [] + + + Examples: + # Find the next IP for the given inputs + $ ipinfo tool next 1.1.1.0 + + # Find next IP from stdin. + $ cat /path/to/file1.txt | ipinfo tool next + + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + prev get the previous IP of the input IP + Usage: + ipinfo tool prev [] + + + Examples: + # Find the previous IP for the given inputs + $ ipinfo tool prev 1.1.1.0 + + # Find prev IP from stdin. + $ cat /path/to/file1.txt | ipinfo tool prev + + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_v4 reports whether input is an IPv4 address. + Usage: + ipinfo tool is_v4 [] + + + Examples: + # Check CIDR. + $ ipinfo tool is_v4 1.1.1.0/30 + + # Check IP range. + $ ipinfo tool is_v4 1.1.1.0-1.1.1.244 + + # Check for file. + $ ipinfo tool is_v4 /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_v4 + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_v6 reports whether input is an IPv6 address. + Usage: + ipinfo tool is_v6 [] + + Examples: + # Check CIDR. + $ ipinfo tool is_v6 2001:db8::/32 + + # Check IP range. + $ ipinfo tool is_v6 2001:db8::1-2001:db8::10 + + # Check for file. + $ ipinfo tool is_v6 /path/to/file1.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_v6 + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_valid reports whether an IP is valid. + Usage: + ipinfo tool is_valid + + Examples: + ipinfo is_valid "190.87.89.1" + ipinfo is_valid "2001:0db8:85a3:0000:0000:8a2e:0370:7334" + ipinfo is_valid "::" + ipinfo is_valid "0" + ipinfo is_valid "" + + + is_one_ip checks whether a CIDR or IP Range contains exactly one IP. + Usage: + ipinfo tool is_one_ip [] + + Examples: + # Check CIDR. + $ ipinfo tool is_one_ip 1.1.1.0/30 + + # Check IP. + $ ipinfo tool is_one_ip 1.1.1.1 + + # Check IP range. + $ ipinfo tool is_one_ip 1.1.1.1-2.2.2.2 + + # Check for file. + $ ipinfo tool is_one_ip /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_one_ip + + + unmap returns ip with any IPv4-mapped IPv6 address prefix removed. + Usage: + ipinfo tool unmap [] + + Examples: + ipinfo tool unmap "::ffff:8.8.8.8" + ipinfo tool unmap "192.180.32.1" + ipinfo tool unmap "::ffff:192.168.1.1" + + + lower get start IP of IPs, IP ranges, and CIDRs. + Usage: + ipinfo tool lower [] + + Examples: + # Finds lower IP for CIDR. + $ ipinfo tool lower 192.168.1.0/24 + + # Finds lower IP for IP range. + $ ipinfo tool lower 1.1.1.0-1.1.1.244 + + # Finds lower IPs from stdin. + $ cat /path/to/file.txt | ipinfo tool lower + + # Find lower IPs from file. + $ ipinfo tool lower /path/to/file1.txt + upper get end IP of IPs, IP ranges, and CIDRs. + Usage: + ipinfo tool upper [] + + Examples: + # Finds upper IP for CIDR. + $ ipinfo tool upper 192.168.1.0/24 + + # Finds upper IP for IP range. + $ ipinfo tool upper 1.1.1.0-1.1.1.244 + + # Finds upper IPs from stdin. + $ cat /path/to/file.txt | ipinfo tool upper + + # Find upper IPs from file. + $ ipinfo tool upper /path/to/file1.txt + + + is_v4in6 get whether the IP is an IPv4-mapped IPv6 address. + Usage: + ipinfo tool is_v4in6 [] + + Examples: + ipinfo is_v4in6 "::7f00:1" + ipinfo is_v4in6 "::ffff" + ipinfo is_v4in6 "::ffff:8.8.8.8" + ipinfo is_v4in6 "::ffff:192.0.2.1 + + + ip2n converts an IPv4 or IPv6 address to its decimal representation. + Usage: + ipinfo tool ip2n + + Examples: + ipinfo ip2n "190.87.89.1" + ipinfo ip2n "2001:0db8:85a3:0000:0000:8a2e:0370:7334" + ipinfo ip2n "2001:0db8:85a3::8a2e:0370:7334" + ipinfo ip2n "::7334" + ipinfo ip2n "7334::" + + + n2ip evaluates a mathematical expression and converts it to an IPv4 or IPv6. + Usage: + ipinfo tool n2ip [] + + + Examples: + ipinfo n2ip "4294967295 + 87" + ipinfo n2ip "4294967295" --ipv6 + ipinfo n2ip -6 "201523715" + ipinfo n2ip "51922968585348276285304963292200960" + ipinfo n2ip "a:: - 4294967295" + + Options: + --ipv6, -6 + force conversion to IPv6 address + + + n2ip6 evaluates a mathematical expression and converts it to an IPv6. + Usage: + ipinfo tool n2ip6 [] + + + Examples: + ipinfo n2ip6 "4294967295 + 87" + ipinfo n2ip6 "4294967295" + ipinfo n2ip6 "201523715" + ipinfo n2ip6 "51922968585348276285304963292200960" + ipinfo n2ip6 "a:: - 4294967295" + + + prefix misc. prefix tools related to CIDRs. + Usage: + ipinfo tool prefix [] [] + + Commands: + addr returns the base IP address of a prefix. + Usage: + ipinfo tool prefix addr + + Examples: + # CIDR Valid Examples. + $ ipinfo tool prefix addr 192.168.0.0/16 + $ ipinfo tool prefix addr 10.0.0.0/8 + $ ipinfo tool prefix addr 2001:0db8:1234::/48 + $ ipinfo tool prefix addr 2606:2800:220:1::/64 + + # CIDR Invalid Examples. + $ ipinfo tool prefix addr 192.168.0.0/40 + $ ipinfo tool prefix addr 2001:0db8:1234::/129 + + + bits returns the length of a prefix and reports -1 if invalid. + Usage: + ipinfo tool prefix bits + + Examples: + # CIDR Valid Examples. + $ ipinfo tool prefix bits 192.168.0.0/16 + $ ipinfo tool prefix bits 10.0.0.0/8 + $ ipinfo tool prefix bits 2001:0db8:1234::/48 + $ ipinfo tool prefix bits 2606:2800:220:1::/64 + + # CIDR Invalid Examples. + $ ipinfo tool prefix bits 192.168.0.0/40 + $ ipinfo tool prefix bits 2001:0db8:1234::/129 + + + masked returns canonical form of a prefix, masking off non-high bits, and returns the zero if invalid. + Usage: + ipinfo tool prefix masked + + Examples: + # CIDR Valid Examples. + $ ipinfo tool prefix masked 192.168.0.0/16 + $ ipinfo tool prefix masked 10.0.0.0/8 + $ ipinfo tool prefix masked 2001:0db8:1234::/48 + $ ipinfo tool prefix masked 2606:2800:220:1::/64 + + # CIDR Invalid Examples. + $ ipinfo tool prefix masked 192.168.0.0/40 + $ ipinfo tool prefix masked 2001:0db8:1234::/129 + + + is_valid reports whether a prefix is valid. + Usage: + ipinfo tool prefix is_valid + + Examples: + # CIDR Valid Examples. + $ ipinfo tool prefix is_valid 192.168.0.0/16 + $ ipinfo tool prefix is_valid 10.0.0.0/8 + $ ipinfo tool prefix is_valid 2001:0db8:1234::/48 + $ ipinfo tool prefix is_valid 2606:2800:220:1::/64 + + # CIDR Invalid Examples. + $ ipinfo tool prefix is_valid 192.168.0.0/40 + $ ipinfo tool prefix is_valid 2001:0db8:1234::/129 + + is_loopback reports whether an IP is a valid loopback address. + Usage: + ipinfo tool is_loopback [] + + Examples: + $ ipinfo tool is_loopback 127.0.0.0 + $ ipinfo tool is_loopback 160.0.0.0 + $ ipinfo tool is_loopback ::1 + $ ipinfo tool is_loopback fe08::2 + + # Check CIDR. + $ ipinfo tool is_loopback 127.0.0.0/32 + $ ipinfo tool is_loopback 128.0.0.0/32 + $ ipinfo tool is_loopback ::1/128 + $ ipinfo tool is_loopback fe08::2/64 + + # Check IP range. + $ ipinfo tool is_loopback 127.0.0.1-127.20.1.244 + $ ipinfo tool is_loopback 128.0.0.1-128.30.1.125 + + # Check for file. + $ ipinfo tool is_loopback /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_loopback + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_multicast reports whether an IP is a valid multicast address. + Usage: + ipinfo tool is_multicast [] + + Examples: + $ ipinfo tool is_multicast 239.0.0.0 + $ ipinfo tool is_multicast 127.0.0.0 + $ ipinfo tool is_multicast ff00:: + $ ipinfo tool is_multicast ::1 + + # Check CIDR. + $ ipinfo tool is_multicast 239.0.0.0/32 + $ ipinfo tool is_multicast 139.0.0.0/32 + $ ipinfo tool is_multicast ff00::1/64 + $ ipinfo tool is_multicast ::1/64 + + # Check IP range. + $ ipinfo tool is_multicast 239.0.0.0-239.255.255.1 + $ ipinfo tool is_multicast 240.0.0.0-240.255.255.1 + $ ipinfo tool is_multicast ff00::1-ff00::ffff + $ ipinfo tool is_multicast ::1-::ffff + + # Check for file. + $ ipinfo tool is_multicast /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_multicast + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_unspecified reports whether an IP is an unspecified address. + Usage: + ipinfo tool is_unspecified [] + + Examples: + $ ipinfo tool is_unspecified 0.0.0.0 + $ ipinfo tool is_unspecified 124.198.16.8 + $ ipinfo tool is_unspecified :: + $ ipinfo tool is_unspecified fe08::1 + + # Check for file. + $ ipinfo tool is_unspecified /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_unspecified + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_global_unicast reports whether an IP is a global unicast address. + Usage: + ipinfo tool is_global_unicast [] + + Examples: + $ ipinfo tool is_global_unicast 10.255.0.0 + $ ipinfo tool is_global_unicast 255.255.255.255 + $ ipinfo tool is_global_unicast 2000::1 + $ ipinfo tool is_global_unicast ff00::1 + + # Check CIDR. + $ ipinfo tool is_global_unicast 10.255.0.0/32 + $ ipinfo tool is_global_unicast 255.255.255.255/32 + $ ipinfo tool is_global_unicast 2000::1/64 + $ ipinfo tool is_global_unicast ff00::1/64 + + # Check IP range. + $ ipinfo tool is_global_unicast 10.0.0.1-10.8.95.6 + $ ipinfo tool is_global_unicast 0.0.0.0-0.255.95.6 + $ ipinfo tool is_global_unicast 2000::1-2000::ffff + $ ipinfo tool is_global_unicast ff00::1-ff00::ffff + + # Check for file. + $ ipinfo tool is_global_unicast /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_global_unicast + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_link_local_unicast reports whether IP is a link local unicast. + Usage: + ipinfo tool is_link_local_unicast [] + + Examples: + $ ipinfo tool is_link_local_unicast 169.254.0.0 + $ ipinfo tool is_link_local_unicast 127.0.0.0 + $ ipinfo tool is_link_local_unicast fe80::1 + $ ipinfo tool is_link_local_unicast ::1 + + # Check CIDR. + $ ipinfo tool is_link_local_unicast 169.254.0.0/32 + $ ipinfo tool is_link_local_unicast 139.0.0.0/32 + $ ipinfo tool is_link_local_unicast fe80::1/64 + $ ipinfo tool is_link_local_unicast ::1/64 + + # Check IP range. + $ ipinfo tool is_link_local_unicast 169.254.0.0-169.254.255.1 + $ ipinfo tool is_link_local_unicast 240.0.0.0-240.255.255.1 + $ ipinfo tool is_link_local_unicast fe80::1-feb0::1 + $ ipinfo tool is_link_local_unicast ::1-::ffff + + # Check for file. + $ ipinfo tool is_link_local_unicast /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_link_local_unicast + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_link_local_multicast reports whether IP is a link local multicast address. + Usage: + ipinfo tool is_link_local_multicast [] + + Examples: + $ ipinfo tool is_link_local_multicast 224.0.0.0 + $ ipinfo tool is_link_local_multicast 169.200.0.0 + $ ipinfo tool is_link_local_multicast ff02::2 + $ ipinfo tool is_link_local_multicast fe80:: + + # Check CIDR. + $ ipinfo tool is_link_local_multicast 224.0.0.0/32 + $ ipinfo tool is_link_local_multicast 169.200.0.0/32 + $ ipinfo tool is_link_local_multicast ff02::1/64 + $ ipinfo tool is_link_local_multicast fe80::1/64 + + # Check IP range. + $ ipinfo tool is_link_local_multicast 224.0.0.1-224.255.255.255 + $ ipinfo tool is_link_local_multicast 169.254.0.1-169.254.255.0 + $ ipinfo tool is_link_local_multicast ff02::1-ff02::ffff + $ ipinfo tool is_link_local_multicast fe80::1-fe80::ffff + + # Check for file. + $ ipinfo tool is_link_local_multicast /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_link_local_multicast + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + is_interface_local_multicast reports whether IP is an interface local multicast. + Usage: + ipinfo tool is_interface_local_multicast [] + + Examples: + $ ipinfo tool is_interface_local_multicast ff01::1 + $ ipinfo tool is_interface_local_multicast ::1 + + # Check CIDR. + $ ipinfo tool is_interface_local_multicast ff01::ffff/32 + $ ipinfo tool is_interface_local_multicast ff03::ffff/32 + + # Check IP range. + $ ipinfo tool is_interface_local_multicast ff01::1-ff01:ffff::1 + $ ipinfo tool is_interface_local_multicast ff03::1-ff03:ffff::1 + + # Check for file. + $ ipinfo tool is_interface_local_multicast /path/to/file.txt + + # Check entries from stdin. + $ cat /path/to/file1.txt | ipinfo tool is_interface_local_multicast + + Options: + --quiet, -q + quiet mode; suppress additional output. + + + Examples: + ipinfo tool + + + ipinfo download Download free ipinfo database files. + Usage: + ipinfo download [] [] + + Examples: + # Download country database in csv format. + $ ipinfo download country -f csv > country.csv + $ ipinfo download country-asn country_asn.mmdb + + Databases: + asn free ipinfo asn database. + country free ipinfo country database. + country-asn free ipinfo country-asn database. + + Options: + --token , -t + use as API token. + + Outputs: + --compress, -c + save the file in compressed format. + default: false. + --format, -f + output format of the database file. + default: mmdb. + + + ipinfo cache Manage the cache. + Usage: + ipinfo cache [] [clear] + + Examples: + # Clear all data currently in the cache. + $ ipinfo cache clear + + + ipinfo config Manage the configuration. + Usage: + ipinfo config [=...] + + Examples: + $ ipinfo config cache=disable + $ ipinfo config token=testtoken cache=enable + + Configurations: + cache= + Control whether the cache is enabled or disabled. + open_browser= + Control whether the links should open the browser or not. + token= + Save a token for use when querying the API. + (Token will not be validated). + + + ipinfo quota Print the request quota of your account. + Usage: + ipinfo quota [] + + Options: + --detailed, -d + show a detailed view of all available limits. + default: false. + + + ipinfo init Login or signup for an account. + Usage: + ipinfo init [] [] + + + Examples: + # Login command with token flag. + $ ipinfo init --token + + # Authentication without token flag. + $ ipinfo init + + Options: + --token , -t + token to login with. + (this is potentially unsafe; let the CLI prompt you instead). + --no-check + disable checking if the token is valid or not. + default: false. + + + ipinfo logout Delete your current API token session. + Usage: + ipinfo logout + + + ipinfo completion Install or output shell auto-completion script. + Usage: + ipinfo completion [] [install | bash | zsh | fish] + + Description: + Install or print out the code needed to do shell auto-completion. + + The current explicitly supported shells are: + - bash + - zsh + - fish + + Examples: + # Attempt auto-installation on any of the supported shells. + $ ipinfo completion install + + # Output auto-completion script for bash for manual installation. + $ ipinfo completion bash + + # Output auto-completion script for zsh for manual installation. + $ ipinfo completion zsh + + # Output auto-completion script for fish for manual installation. + $ ipinfo completion fish + + + ipinfo version Show the current version. + Examples: + ipinfo version + + +Options: + --token Use as the API token. + --nocache Do not use the cache. + --version Show the version number. + --help, -h Show this help message. + --pretty, -p Output pretty format. + + +Examples: + ipinfo myip + ipinfo --token --json bulk --file ip_list.txt --output results.json + ipinfo completion --install bash` diff --git a/ipinfo/ipinfo.1 b/ipinfo/ipinfo.1 deleted file mode 100644 index 258f4a1a..00000000 --- a/ipinfo/ipinfo.1 +++ /dev/null @@ -1,210 +0,0 @@ -.TH ipinfo 1 "November 2023" "ipinfo" - -.SH NAME -ipinfo \- IP information lookup tool - -.SH SYNOPSIS -.B ipinfo -[\fICOMMAND\fP] [\fIOPTIONS\fP] [\fIARGUMENTS\fP] - -.SH DESCRIPTION -The -.B ipinfo -command is a versatile tool for retrieving information related to IP addresses, Autonomous System Numbers (ASNs), and various related operations. It provides detailed insights into IP addresses, ASN details, and offers a range of utilities for managing and analyzing IP-related information. - -When invoked without any command or options, it provides a summary. - -.SH COMMANDS -.TP -.B -Look up details for an IP address, e.g. 8.8.8.8. - -.TP -.B -Look up details for an ASN, e.g. AS123 or as123. - -.TP -.B myip -Get details for your IP. - -.TP -.B bulk -Get details for multiple IPs in bulk. - -.TP -.B asn -Tools related to ASNs. - -.TP -.B summarize -Get summarized data for a group of IPs. - -.TP -.B map -Open a URL to a map showing the locations of a group of IPs. - -.TP -.B prips -Print IP list from CIDR or range. - -.TP -.B grepip -Grep for IPs matching criteria from any source. - -.TP -.B matchip -Print the overlapping IPs and subnets. - -.TP -.B grepdomain -Grep for domains matching criteria from any source. - -.TP -.B cidr2range -Convert CIDRs to IP ranges. - -.TP -.B cidr2ip -Convert CIDRs to individual IPs within those CIDRs. - -.TP -.B range2cidr -Convert IP ranges to CIDRs. - -.TP -.B range2ip -Convert IP ranges to individual IPs within those ranges. - -.TP -.B randip -Generates random IPs. - -.TP -.B splitcidr -Splits a larger CIDR into smaller CIDRs. - -.TP -.B mmdb -Read, import, and export mmdb files. - -.TP -.B calc -Evaluates a mathematical expression that may contain IP addresses. - -.TP -.B tool -Misc. tools related to IPs, IP ranges, and CIDRs. - -.TP -.B download -Download free ipinfo database files. - -.TP -.B cache -Manage the cache. - -.TP -.B config -Manage the config. - -.TP -.B quota -Print the request quota of your account. - -.TP -.B init -Login or signup account. - -.TP -.B logout -Delete your current API token session. - -.TP -.B completion -Install or output shell auto-completion script. - -.TP -.B version -Show current version. - -.SH OPTIONS - -.TP -.B GENERAL OPTIONS: - - -.TP -.B --token , -t -Use as API token. - -.TP -.B --nocache -Do not use the cache. - -.TP -.B --version, -v -Show binary release number. - -.TP -.B --help, -h -Show help. - - -.TP -.B OUTPUT OPTIONS: - - -.TP -.B --field , -f -Lookup only specific fields in the output. -Field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. -Multiple field names must be separated by commas. - -.TP -.B --nocolor -Disable colored output. - - -.TP -.B FORMAT OPTIONS: - - -.TP -.B --pretty, -p -Output pretty format. - -.TP -.B --json, -j -Output JSON format. - -.TP -.B --csv, -c -Output CSV format. - -.TP -.B --yaml, -y -Output YAML format. - -.SH EXAMPLES -.TP -.B ipinfo myip -Get details for your IP. - -.TP -.B ipinfo 8.8.8.8 -Look up details for a specific ip address. - -.TP -.B ipinfo -Get a summary regarding the command. - -.TP -.B ipinfo grepdomain -n file.txt -Access subcommands through the main command. - -.SH SEE ALSO -.BR ipinfo-asn (1), -.BR ipinfo-bulk (1). - -.SH REPORTING BUGS -Report bugs to: https://github.com/ipinfo/cli/issues diff --git a/ipinfo/main.go b/ipinfo/main.go index ede35331..c24d02a5 100644 --- a/ipinfo/main.go +++ b/ipinfo/main.go @@ -15,6 +15,7 @@ var version = "3.2.0" // global flags. var fHelp bool +var fLess bool var fNoCache bool var fNoColor bool diff --git a/scripts/build-archive-all.sh b/scripts/build-archive-all.sh index a3568925..fa940da5 100755 --- a/scripts/build-archive-all.sh +++ b/scripts/build-archive-all.sh @@ -10,7 +10,6 @@ ROOT=$DIR/.. CLI=$1 VSN=$2 - if [ -z "$CLI" ]; then echo "require cli as first parameter" 2>&1 exit 1 @@ -45,9 +44,4 @@ cd .. rm -rf $ROOT/${CLI}/dist/usr mkdir -p $ROOT/${CLI}/dist/usr/local/bin cp $ROOT/build/${CLI}_${VSN}_linux_amd64 $ROOT/${CLI}/dist/usr/local/bin/${CLI} - -# Copy man page to the appropriate location -mkdir -p $ROOT/${CLI}/dist/usr/share/man/man1 -cp $ROOT/ipinfo/ipinfo.1 $ROOT/${CLI}/dist/usr/share/man/man1/ - -dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb +dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb \ No newline at end of file From 2aa02fb6b3e345a8252a60fc5c357dc687f5947c Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Tue, 12 Dec 2023 14:37:11 +0500 Subject: [PATCH 04/10] Revision: Use the PAGER environment variable to determine the pager tool --- ipinfo/cmd_default.go | 15 +++++++++++---- ipinfo/detailed_help.go | 8 +------- ipinfo/main.go | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index 2074acc5..cca1746d 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -83,7 +83,14 @@ Options: func pageHelp(detailedHelp string) error { - cmd := exec.Command("less") + pagerCmd := os.Getenv("PAGER") + + if pagerCmd == "" { + // If PAGER is not set, use a default pager (e.g., less) + pagerCmd = "less" + } + + cmd := exec.Command(pagerCmd) // Create an io.Reader from the detailed help string reader := io.Reader(strings.NewReader(detailedHelp)) @@ -109,7 +116,7 @@ func cmdDefault() (err error) { pflag.BoolVar(&fNoCache, "nocache", false, "disable the cache.") pflag.BoolVarP(&fVsn, "version", "v", false, "print binary release number.") pflag.BoolVarP(&fHelp, "short-help", "h", false, "show help.") - pflag.BoolVar(&fLess, "help", false, "use less for detailed help") + pflag.BoolVar(&fPage, "help", false, "use pager for detailed help") pflag.StringSliceVarP(&fField, "field", "f", nil, "specific field to lookup.") pflag.BoolVarP(&fPretty, "pretty", "p", true, "output pretty format.") pflag.BoolVarP(&fJSON, "json", "j", true, "output JSON format. (default)") @@ -127,8 +134,8 @@ func cmdDefault() (err error) { return nil } - if fLess { - // Read the contents of the help file and pipe to less + if fPage { + // Read the string and display it using a pager err = pageHelp(DetailedHelp) return err } diff --git a/ipinfo/detailed_help.go b/ipinfo/detailed_help.go index cdd3116c..0277b89b 100644 --- a/ipinfo/detailed_help.go +++ b/ipinfo/detailed_help.go @@ -1211,10 +1211,4 @@ Options: --nocache Do not use the cache. --version Show the version number. --help, -h Show this help message. - --pretty, -p Output pretty format. - - -Examples: - ipinfo myip - ipinfo --token --json bulk --file ip_list.txt --output results.json - ipinfo completion --install bash` + --pretty, -p Output pretty format.` diff --git a/ipinfo/main.go b/ipinfo/main.go index c24d02a5..fd817949 100644 --- a/ipinfo/main.go +++ b/ipinfo/main.go @@ -15,7 +15,7 @@ var version = "3.2.0" // global flags. var fHelp bool -var fLess bool +var fPage bool var fNoCache bool var fNoColor bool From a356bee4d029a3cdd975f459c1b8b235cd48ebaf Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Wed, 13 Dec 2023 11:59:50 +0500 Subject: [PATCH 05/10] incorporated the suggested fixes --- ipinfo/cmd_default.go | 41 +++++++++++------------------------- ipinfo/main.go | 2 +- lib/help_detailed.go | 31 +++++++++++++++++++++++++++ scripts/build-archive-all.sh | 1 + 4 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 lib/help_detailed.go diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index cca1746d..dfce492d 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -4,11 +4,8 @@ import ( _ "embed" "errors" "fmt" - "io" "net" "os" - "os/exec" - "strings" "github.com/fatih/color" "github.com/ipinfo/cli/lib" @@ -81,27 +78,6 @@ Options: `, progBase) } -func pageHelp(detailedHelp string) error { - - pagerCmd := os.Getenv("PAGER") - - if pagerCmd == "" { - // If PAGER is not set, use a default pager (e.g., less) - pagerCmd = "less" - } - - cmd := exec.Command(pagerCmd) - - // Create an io.Reader from the detailed help string - reader := io.Reader(strings.NewReader(detailedHelp)) - cmd.Stdin = reader - - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - return cmd.Run() -} - func cmdDefault() (err error) { var ips []net.IP var fTok string @@ -115,8 +91,8 @@ func cmdDefault() (err error) { pflag.StringVarP(&fTok, "token", "t", "", "the token to use.") pflag.BoolVar(&fNoCache, "nocache", false, "disable the cache.") pflag.BoolVarP(&fVsn, "version", "v", false, "print binary release number.") - pflag.BoolVarP(&fHelp, "short-help", "h", false, "show help.") - pflag.BoolVar(&fPage, "help", false, "use pager for detailed help") + pflag.BoolVarP(&fHelp, "", "h", false, "show help.") + pflag.BoolVar(&fHelpDetailed, "help", false, "show detailed help") pflag.StringSliceVarP(&fField, "field", "f", nil, "specific field to lookup.") pflag.BoolVarP(&fPretty, "pretty", "p", true, "output pretty format.") pflag.BoolVarP(&fJSON, "json", "j", true, "output JSON format. (default)") @@ -134,10 +110,17 @@ func cmdDefault() (err error) { return nil } - if fPage { + if fHelpDetailed { // Read the string and display it using a pager - err = pageHelp(DetailedHelp) - return err + err = lib.HelpDetailed(DetailedHelp) + + //if error occurs running the pager, display the default help + if err != nil { + fmt.Fprintf(os.Stderr, "Error displaying detailed help: %v\n\n", err) + printHelpDefault() + } + + return nil } if fVsn { diff --git a/ipinfo/main.go b/ipinfo/main.go index fd817949..53343841 100644 --- a/ipinfo/main.go +++ b/ipinfo/main.go @@ -15,7 +15,7 @@ var version = "3.2.0" // global flags. var fHelp bool -var fPage bool +var fHelpDetailed bool var fNoCache bool var fNoColor bool diff --git a/lib/help_detailed.go b/lib/help_detailed.go new file mode 100644 index 00000000..bd8dff28 --- /dev/null +++ b/lib/help_detailed.go @@ -0,0 +1,31 @@ +package lib + +import ( + "io" + "os" + "os/exec" + "strings" +) + +func HelpDetailed(detailedHelp string) error { + + pagerCmd := os.Getenv("PAGER") + + if pagerCmd == "" { + // If PAGER is not set, use a default pager (e.g., less) + pagerCmd = "less" + } + + cmd := exec.Command(pagerCmd) + + // Create an io.Reader from the detailed help string + reader := io.Reader(strings.NewReader(detailedHelp)) + cmd.Stdin = reader + + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + // returns an error if the command doesn't execute properly. Otherwise, it returns nil and executes the command + return cmd.Run() + +} diff --git a/scripts/build-archive-all.sh b/scripts/build-archive-all.sh index fa940da5..4a6258c8 100755 --- a/scripts/build-archive-all.sh +++ b/scripts/build-archive-all.sh @@ -44,4 +44,5 @@ cd .. rm -rf $ROOT/${CLI}/dist/usr mkdir -p $ROOT/${CLI}/dist/usr/local/bin cp $ROOT/build/${CLI}_${VSN}_linux_amd64 $ROOT/${CLI}/dist/usr/local/bin/${CLI} + dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb \ No newline at end of file From b2977aeb851c275278a66514c2da28d84eea0737 Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Wed, 13 Dec 2023 13:22:41 +0500 Subject: [PATCH 06/10] incorporated suggested changes --- debian/rules | 2 +- ipinfo/cmd_default.go | 9 +-------- lib/help_detailed.go | 16 +++++++--------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/debian/rules b/debian/rules index b6f61f4f..6d3a03c1 100755 --- a/debian/rules +++ b/debian/rules @@ -1,3 +1,3 @@ #!/usr/bin/make -f %: - PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang \ No newline at end of file + PATH=${PATH}:/usr/lib/go-1.18/bin dh $@ --builddirectory=_build --buildsystem=golang --with=golang diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index dfce492d..0a775447 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -112,14 +112,7 @@ func cmdDefault() (err error) { if fHelpDetailed { // Read the string and display it using a pager - err = lib.HelpDetailed(DetailedHelp) - - //if error occurs running the pager, display the default help - if err != nil { - fmt.Fprintf(os.Stderr, "Error displaying detailed help: %v\n\n", err) - printHelpDefault() - } - + lib.HelpDetailed(DetailedHelp, printHelpDefault) return nil } diff --git a/lib/help_detailed.go b/lib/help_detailed.go index bd8dff28..f02f7562 100644 --- a/lib/help_detailed.go +++ b/lib/help_detailed.go @@ -7,25 +7,23 @@ import ( "strings" ) -func HelpDetailed(detailedHelp string) error { - +func HelpDetailed(detailedHelp string, printHelpDefault func()) error { pagerCmd := os.Getenv("PAGER") - if pagerCmd == "" { // If PAGER is not set, use a default pager (e.g., less) pagerCmd = "less" } cmd := exec.Command(pagerCmd) - - // Create an io.Reader from the detailed help string reader := io.Reader(strings.NewReader(detailedHelp)) cmd.Stdin = reader - cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - // returns an error if the command doesn't execute properly. Otherwise, it returns nil and executes the command - return cmd.Run() - + err := cmd.Run() + //if an error occurs running the pager, display the default help + if err != nil { + printHelpDefault() + } + return nil } From 736158a91cac3cc352ff78965463f483b215d189 Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Wed, 13 Dec 2023 13:41:24 +0500 Subject: [PATCH 07/10] slight code refactoring --- lib/help_detailed.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/help_detailed.go b/lib/help_detailed.go index f02f7562..34475373 100644 --- a/lib/help_detailed.go +++ b/lib/help_detailed.go @@ -20,9 +20,8 @@ func HelpDetailed(detailedHelp string, printHelpDefault func()) error { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - err := cmd.Run() //if an error occurs running the pager, display the default help - if err != nil { + if err := cmd.Run(); err != nil { printHelpDefault() } return nil From 47bf90fda400f023bc611666bacce395a38bef3c Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Wed, 13 Dec 2023 16:49:51 +0500 Subject: [PATCH 08/10] incorporated the suggested changes --- ipinfo/cmd_default.go | 1 - ipinfo/detailed_help.go | 1264 ++-------------------------------- lib/help_detailed.go | 4 +- scripts/build-archive-all.sh | 3 +- 4 files changed, 60 insertions(+), 1212 deletions(-) diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index 0a775447..52d5a224 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -1,7 +1,6 @@ package main import ( - _ "embed" "errors" "fmt" "net" diff --git a/ipinfo/detailed_help.go b/ipinfo/detailed_help.go index 0277b89b..55ccce23 100644 --- a/ipinfo/detailed_help.go +++ b/ipinfo/detailed_help.go @@ -1,1214 +1,62 @@ package main -var DetailedHelp = `ipinfo - IP information lookup tool. - -Usage: - ipinfo [options] [arguments] +var DetailedHelp = `Usage: ipinfo [] [] Commands: - ipinfo Lookup details for a specific IP address. - Options: - --field , -f - Lookup only specific fields in the output. - --nocolor - Disable colored output. - --json, -j - Output JSON format. - --csv, -c - Output CSV format. - --yaml, -y - Output YAML format. - - Examples: - ipinfo 8.8.8.8 - ipinfo 8.8.8.8 --field hostname,city - - - ipinfo Lookup details for a specific ASN. - Options: - --field - Lookup only specific fields in the output. - --nocolor - Disable colored output. - --json, -j - Output JSON format. - --csv, -c - Output CSV format. - --yaml, -y - Output YAML format. - - Examples: - ipinfo - ipinfo --field hostname,city - - - ipinfo myip Get details for your IP. - Usage: - ipinfo myip [] - - Options: - --field - Lookup only specific fields in the output. - --nocolor - Disable colored output. - --json, -j - Output JSON format. - --csv, -c - Output CSV format. - --yaml, -y - Output YAML format. - - Examples: - ipinfo myip - ipinfo myip --field hostname,city - - - ipinfo bulk Get details for multiple IPs in bulk. - Usage: - ipinfo bulk [] - - Options: - --field Lookup only specific fields in the output. - --json, -j Output JSON format. - --csv, -c Output CSV format. - --yaml, -y Output YAML format. - - Examples: - # Lookup all IPs from stdin ('-' can be implied). - $ ipinfo prips 8.8.8.0/24 | ipinfo bulk - $ ipinfo prips 8.8.8.0/24 | ipinfo bulk - - - # Lookup all IPs in 2 files. - $ ipinfo bulk /path/to/iplist1.txt /path/to/iplist2.txt - - # Lookup all IPs from CIDR. - $ ipinfo bulk 8.8.8.0/24 - - # Lookup all IPs from multiple CIDRs. - $ ipinfo bulk 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 - - # Lookup all IPs in an IP range. - $ ipinfo bulk 8.8.8.0-8.8.8.255 - - # Lookup all IPs from multiple sources simultaneously. - $ ipinfo bulk 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt - - - ipinfo asn Tools related to ASNs. - Usage: - ipinfo asn [] - - Commands: - bulk lookup ASNs in bulk - - - ipinfo summarize Get summarized data for a group of IPs. - Usage: - ipinfo summarize [] - - Options: - --json, -j - Output JSON format. - --csv, -c - Output CSV format. - --yaml, -y - Output YAML format. - - Examples: - # Summarize all IPs from stdin ('-' can be implied). - $ ipinfo prips 8.8.8.0/24 | ipinfo summarize - $ ipinfo prips 8.8.8.0/24 | ipinfo summarize - - - # Summarize all IPs in 2 files. - $ ipinfo summarize /path/to/iplist1.txt /path/to/iplist2.txt - - # Summarize all IPs from CIDR. - $ ipinfo summarize 8.8.8.0/24 - - # Summarize all IPs from multiple CIDRs. - $ ipinfo summarize 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 - - # Summarize all IPs in an IP range. - $ ipinfo summarize 8.8.8.0-8.8.8.255 - - # Summarize all IPs from multiple sources simultaneously. - $ ipinfo summarize 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt - - - ipinfo map Open a URL to a map showing the locations of a group of IPs. - Usage: - ipinfo map [] - - Options: - --no-browser - don't open the map link in the browser - default is false. - - Examples: - # Map all IPs from stdin ('-' can be implied). - $ ipinfo prips 8.8.8.0/24 | ipinfo map - $ ipinfo prips 8.8.8.0/24 | ipinfo map - - - # Map all IPs in 2 files. - $ ipinfo map /path/to/iplist1.txt /path/to/iplist2.txt - - # Map all IPs from CIDR. - $ ipinfo map 8.8.8.0/24 - - # Map all IPs from multiple CIDRs. - $ ipinfo map 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 - - # Map all IPs in an IP range. - $ ipinfo map 8.8.8.0-8.8.8.255 - - # Map all IPs from multiple sources simultaneously. - $ ipinfo map 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt - - - ipinfo prips Print IP list from CIDR or range. - Usage: - ipinfo prips [] - - Examples: - # List all IPs in a CIDR. - $ ipinfo prips 8.8.8.0/24 - - # List all IPs in multiple CIDRs. - $ ipinfo prips 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 - - # List all IPs in an IP range. - $ ipinfo prips 8.8.8.0-8.8.8.255 - - # List all IPs in multiple CIDRs and IP ranges. - $ ipinfo prips 1.1.1.0/30 8.8.8.0-8.8.8.255 2.2.2.0/30 7.7.7.0,7.7.7.10 - - # List all IPs from stdin input (newline-separated). - $ echo '1.1.1.0/30\n8.8.8.0-8.8.8.255\n7.7.7.0,7.7.7.10' | ipinfo prips - - - ipinfo grepip Grep for IPs matching criteria from any source. - Usage: - ipinfo grepip [] - - Options: - --only-matching, -o - print only matched IP in result line, excluding surrounding content. - --no-filename, -h - don't print source of match in result lines when more than 1 source. - --no-recurse - don't recurse into more directories in directory sources. - - Filters: - --ipv4, -4 - match only IPv4 addresses. - --ipv6, -6 - match only IPv6 addresses. - --exclude-reserved, -x - exclude reserved/bogon IPs. - full list can be found at https://ipinfo.io/bogon. - - Examples: - ipinfo grepip -o - - - ipinfo matchip Print the overlapping IPs and subnets. - Usage: - ipinfo matchip [flags] - - Flags: - --expression, -e CIDRs, ip-ranges to to check overlap with. Can be used multiple times. - - Examples: - # Single expression + single file - $ ipinfo matchip 127.0.0.1/24 file1.txt - - # Single expression + multiple files - $ ipinfo matchip 127.0.0.1/24 file1.txt file2.txt file3.txt - - # Multi-expression + any files - $ cat expression-list1.txt | ipinfo matchip -e 127.0.0.1/24 -e 8.8.8.8-8.8.9.10 -e - -e expression-list2.txt file1.txt file2.txt file3.txt - - # First arg is expression - $ ipinfo matchip 8.8.8.8-8.8.9.10 8.8.0.0/16 8.8.0.10 - - - ipinfo gredomain Grep for domains matching criteria from any source. - Usage: - ipinfo grepdomain [] - - Options: - --only-matching, -o - print only matched IP in result line, excluding surrounding content. - --no-filename, -h - don't print source of match in result lines when more than 1 source. - --no-recurse - don't recurse into more directories in directory sources. - - Filters: - --no-punycode, -n - do not convert domains to punycode. - - Examples: - ipinfo grepdomain -o - - - ipinfo cidr2range Convert CIDRs to IP ranges. - Usage: - ipinfo cidr2range [] - - Examples: - # Get the range for CIDR 1.1.1.0/30. - $ ipinfo cidr2range 1.1.1.0/30 - - # Convert CIDR entries to IP ranges in 2 files. - $ ipinfo cidr2range /path/to/file1.txt /path/to/file2.txt - - # Convert CIDR entries to IP ranges from stdin. - $ cat /path/to/file1.txt | ipinfo cidr2range - - # Convert CIDR entries to IP ranges from stdin and a file. - $ cat /path/to/file1.txt | ipinfo cidr2range /path/to/file2.txt - - - ipinfo cidr2ip Convert CIDRs to individual IPs within those CIDRs. - Usage: - ipinfo cidr2ip [] - - Examples: - ipinfo cidr2ip 8.8.8.0/24 - - - ipinfo range2cidr Convert IP ranges to CIDRs. - Usage: - ipinfo range2cidr [] - - Description: - Accepts IP ranges and file paths to files containing IP ranges, converting - them all to CIDRs (and multiple CIDRs if required). - - If a file is input, it is assumed that the IP range to convert is the first - entry of each line. Other data is allowed and copied transparently. - - If multiple CIDRs are needed to represent an IP range on a line with other - data, the data is copied per CIDR required. For example: - - in[0]: "1.1.1.0,1.1.1.2,other-data" - out[0]: "1.1.1.0/31,other-data" - out[1]: "1.1.1.2/32,other-data" - - IP ranges can have the form "" where "" can be "," or - "-", and "" and "" can be any 2 IPs; order does not matter, but - the resulting CIDRs are printed in the order they cover the range. - - Examples: - # Get all CIDRs for range 1.1.1.0-1.1.1.2. - $ ipinfo range2cidr 1.1.1.0-1.1.1.2 - $ ipinfo range2cidr 1.1.1.0,1.1.1.2 - - # Convert all range entries to CIDRs in 2 files. - $ ipinfo range2cidr /path/to/file1.txt /path/to/file2.txt - - # Convert all range entries to CIDRs from stdin. - $ cat /path/to/file1.txt | ipinfo range2cidr - - # Convert all range entries to CIDRs from stdin and a file. - $ cat /path/to/file1.txt | ipinfo range2cidr /path/to/file2.txt - - - ipinfo range2ip Convert IP ranges to individual IPs within those ranges. - Usage: ipinfo range2ip [] - - Description: - Accepts IP ranges and file paths to files containing IP ranges, converting - them all to individual IPs within those ranges. - - $ ipinfo range2ip 8.8.8.0-8.8.8.255 - - IP ranges can be of the form "" where "" can be "," or - "-", and "" and "" can be any 2 IPs; order does not matter. - - - ipinfo randip Generates random IPs. - Usage: - ipinfo randip [] - - Description: - Generate random IPs. - - By default, generates 1 random IPv4 address with starting range 0.0.0.0 and - ending range 255.255.255.255, but can be configured to generate any number of - a combination of IPv4/IPv6 addresses within any range. - - Using --ipv6 or -6 without any starting or ending range will generate a IP - between range of :: to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff. - - Note that only IPv4 or IPv6 IPs can be generated, but not both. - - When generating unique IPs, the range size must not be less than the desired - number of random IPs. - - Options: - --num, -n - number of IPs to generate. - --ipv4, -4 - generate IPv4 IPs. - --ipv6, -6 - generate IPv6 IPs. - --start, -s - starting range of IPs. default: minimum IP possible for IP type selected. - --end, -e - ending range of IPs. default: maximum IP possible for IP type selected. - --exclude-reserved -x - exclude reserved/bogon IPs. full list can be found at https://ipinfo.io/bogon. - --unique, -u - generate unique IPs. - - Examples: - ipinfo randip --count 5 - - - ipinfo splitcidr Splits a larger CIDR into smaller CIDRs. - Usage: - ipinfo splitcidr - - Examples: - ipinfo splitcidr 8.8.8.0/24 25 - - - ipinfo mmdb Read, import, and export mmdb files. - Usage: - ipinfo mmdb [] [] - - Commands: - read read data for IPs in an mmdb file. - Usage: - ipinfo mmdb read [] - - Options: - -f , --format - the output format. - can be "json", "json-compact", "json-pretty", "tsv" or "csv". Note that "json" is short for "json-compact". - default: json. - - import import data in non-mmdb format into mmdb. - Usage: - ipinfo mmdb import [] [] [] - - Options: - Input/Output: - -i , --in - input file name. (e.g. data.csv or - for stdin) - must be in CSV, TSV or JSON. - default: stdin. - -o , --out - output file name. (e.g. sample.mmdb) - default: stdout. - -c, --csv - interpret input file as CSV. - by default, the .csv extension will turn this on. - -t, --tsv - interpret input file as TSV. - by default, the .tsv extension will turn this on. - -j, --json - interpret input file as JSON. - by default, the .json extension will turn this on. - - Fields: - One of the following fields flags, or other flags that implicitly specify - these, must be used, otherwise --fields-from-header is assumed. - - The first field is always implicitly the network field, unless - --range-multicol is used, in which case the first 2 fields are considered - to be start_ip,end_ip. - - When specifying --fields, do not specify the network column(s). - - -f, --fields - explicitly specify the fields to assume exist in the input file. - example: col1,col2,col3 - default: N/A. - --fields-from-header - assume first line of input file is a header, and set the fields as that. - default: true if no other field source is used, false otherwise. - --range-multicol - assume that the network field is actually two columns start_ip,end_ip. - default: false. - --joinkey-col - assume --range-multicol and that the 3rd column is join_key, and ignore - this column when converting to JSON. - default: false. - --no-fields - specify that no fields exist except the implicit network field. - when enabled, --no-network has no effect; the network field is written. - default: false. - --no-network - if --fields-from-header is set, then don't write the network field, which - is assumed to be the *first* field in the header. - default: false. - - Meta: - --ip <4 | 6> - output file's ip version. - default: 6. - -s, --size <24 | 28 | 32> - size of records in the mmdb tree. - default: 32. - -m, --merge - the merge strategy to use when inserting entries that conflict. - none => no merge; only replace conflicts. - toplevel => merge only top-level keys. - recurse => recursively merge. - default: none. - --ignore-empty-values - if enabled, write into /0 with empty values for all fields, and for any - entry, don't write out a field whose value is the empty string. - default: false. - --disallow-reserved - disallow reserved networks to be added to the tree. - default: false. - --alias-6to4 - enable the mapping of some IPv6 networks into the IPv4 network, e.g. - ::ffff:0:0/96, 2001::/32 & 2002::/16. - default: false. - --disable-metadata-pointers - some mmdb readers fail to properly read pointers within metadata. this - allows turning off such pointers. - default: true. - - Example: - # Imports an input file and outputs an mmdb file with default configurations. - $ ipinfo mmdb import input.csv output.mmdb - - - export export data from mmdb format into non-mmdb format. - Usage: - ipinfo mmdb export [] [] - - Options: - Input/Output: - -o , --out - output file name. (e.g. out.csv) - default: if specified, otherwise stdout. - - Format: - -f , --format - the output file format. - can be "csv", "tsv" or "json". - default: csv if output file ends in ".csv", tsv if ".tsv", - json if ".json", otherwise csv. - --no-header - don't output the header for file formats that include one, like - CSV/TSV/JSON. - default: false. - - - diff see the difference between two mmdb files. - Usage: - ipinfo mmdb diff [] - - Description: - Print subnet and record differences between two mmdb files (i.e. do set - difference "(new - old) U (old - new))". - - Options: - --subnets, -s - show subnets difference. - --records, -r - show records difference. - - - metadata print metadata from the mmdb file. - Usage: - ipinfo mmdb metadata [] - - Options: - --nocolor - disable colored output. - - Format: - -f , --format - the metadata output format. - can be "pretty" or "json". - default: pretty. - - - verify check that the mmdb file is not corrupted or invalid. - Usage: - ipinfo mmdb verify [] - - - completion install or output shell auto-completion script. - - - Options: - --nocolor disable colored output. - - - ipinfo calc Evaluates a mathematical expression that may contain IP addresses. - Usage: - ipinfo calc [] - - Examples: - ipinfo calc "2*2828-1" - ipinfo calc "190.87.89.1*2" - ipinfo calc "2001:0db8:85a3:0000:0000:8a2e:0370:7334*6" - - - ipinfo tool Misc. tools related to IPs, IP ranges, and CIDRs. - Usage: - ipinfo tool [] [] - - Commands: - aggregate aggregate IPs, IP ranges, and CIDRs. - Usage: - ipinfo tool aggregate [] - - Description: - Accepts IPv4 IPs and CIDRs, aggregating them efficiently. - - If input contains single IPs, it tries to merge them into the input CIDRs, - otherwise they are printed to the output as they are. - - IP range can be of format , where can either - be a ',' or a '-'. - - - Examples: - # Aggregate two CIDRs. - $ ipinfo tool aggregate 1.1.1.0/30 1.1.1.0/28 - - # Aggregate enteries from 2 files. - $ ipinfo tool aggregate /path/to/file1.txt /path/to/file2.txt - - # Aggregate enteries from stdin. - $ cat /path/to/file1.txt | ipinfo tool aggregate - - # Aggregate enteries from stdin and a file. - $ cat /path/to/file1.txt | ipinfo tool aggregate /path/to/file2.txt - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - next get the next IP of the input IP - Usage: - ipinfo tool next [] - - - Examples: - # Find the next IP for the given inputs - $ ipinfo tool next 1.1.1.0 - - # Find next IP from stdin. - $ cat /path/to/file1.txt | ipinfo tool next - - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - prev get the previous IP of the input IP - Usage: - ipinfo tool prev [] - - - Examples: - # Find the previous IP for the given inputs - $ ipinfo tool prev 1.1.1.0 - - # Find prev IP from stdin. - $ cat /path/to/file1.txt | ipinfo tool prev - - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_v4 reports whether input is an IPv4 address. - Usage: - ipinfo tool is_v4 [] - - - Examples: - # Check CIDR. - $ ipinfo tool is_v4 1.1.1.0/30 - - # Check IP range. - $ ipinfo tool is_v4 1.1.1.0-1.1.1.244 - - # Check for file. - $ ipinfo tool is_v4 /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_v4 - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_v6 reports whether input is an IPv6 address. - Usage: - ipinfo tool is_v6 [] - - Examples: - # Check CIDR. - $ ipinfo tool is_v6 2001:db8::/32 - - # Check IP range. - $ ipinfo tool is_v6 2001:db8::1-2001:db8::10 - - # Check for file. - $ ipinfo tool is_v6 /path/to/file1.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_v6 - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_valid reports whether an IP is valid. - Usage: - ipinfo tool is_valid - - Examples: - ipinfo is_valid "190.87.89.1" - ipinfo is_valid "2001:0db8:85a3:0000:0000:8a2e:0370:7334" - ipinfo is_valid "::" - ipinfo is_valid "0" - ipinfo is_valid "" - - - is_one_ip checks whether a CIDR or IP Range contains exactly one IP. - Usage: - ipinfo tool is_one_ip [] - - Examples: - # Check CIDR. - $ ipinfo tool is_one_ip 1.1.1.0/30 - - # Check IP. - $ ipinfo tool is_one_ip 1.1.1.1 - - # Check IP range. - $ ipinfo tool is_one_ip 1.1.1.1-2.2.2.2 - - # Check for file. - $ ipinfo tool is_one_ip /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_one_ip - - - unmap returns ip with any IPv4-mapped IPv6 address prefix removed. - Usage: - ipinfo tool unmap [] - - Examples: - ipinfo tool unmap "::ffff:8.8.8.8" - ipinfo tool unmap "192.180.32.1" - ipinfo tool unmap "::ffff:192.168.1.1" - - - lower get start IP of IPs, IP ranges, and CIDRs. - Usage: - ipinfo tool lower [] - - Examples: - # Finds lower IP for CIDR. - $ ipinfo tool lower 192.168.1.0/24 - - # Finds lower IP for IP range. - $ ipinfo tool lower 1.1.1.0-1.1.1.244 - - # Finds lower IPs from stdin. - $ cat /path/to/file.txt | ipinfo tool lower - - # Find lower IPs from file. - $ ipinfo tool lower /path/to/file1.txt - upper get end IP of IPs, IP ranges, and CIDRs. - Usage: - ipinfo tool upper [] - - Examples: - # Finds upper IP for CIDR. - $ ipinfo tool upper 192.168.1.0/24 - - # Finds upper IP for IP range. - $ ipinfo tool upper 1.1.1.0-1.1.1.244 - - # Finds upper IPs from stdin. - $ cat /path/to/file.txt | ipinfo tool upper - - # Find upper IPs from file. - $ ipinfo tool upper /path/to/file1.txt - - - is_v4in6 get whether the IP is an IPv4-mapped IPv6 address. - Usage: - ipinfo tool is_v4in6 [] - - Examples: - ipinfo is_v4in6 "::7f00:1" - ipinfo is_v4in6 "::ffff" - ipinfo is_v4in6 "::ffff:8.8.8.8" - ipinfo is_v4in6 "::ffff:192.0.2.1 - - - ip2n converts an IPv4 or IPv6 address to its decimal representation. - Usage: - ipinfo tool ip2n - - Examples: - ipinfo ip2n "190.87.89.1" - ipinfo ip2n "2001:0db8:85a3:0000:0000:8a2e:0370:7334" - ipinfo ip2n "2001:0db8:85a3::8a2e:0370:7334" - ipinfo ip2n "::7334" - ipinfo ip2n "7334::" - - - n2ip evaluates a mathematical expression and converts it to an IPv4 or IPv6. - Usage: - ipinfo tool n2ip [] - - - Examples: - ipinfo n2ip "4294967295 + 87" - ipinfo n2ip "4294967295" --ipv6 - ipinfo n2ip -6 "201523715" - ipinfo n2ip "51922968585348276285304963292200960" - ipinfo n2ip "a:: - 4294967295" - - Options: - --ipv6, -6 - force conversion to IPv6 address - - - n2ip6 evaluates a mathematical expression and converts it to an IPv6. - Usage: - ipinfo tool n2ip6 [] - - - Examples: - ipinfo n2ip6 "4294967295 + 87" - ipinfo n2ip6 "4294967295" - ipinfo n2ip6 "201523715" - ipinfo n2ip6 "51922968585348276285304963292200960" - ipinfo n2ip6 "a:: - 4294967295" - - - prefix misc. prefix tools related to CIDRs. - Usage: - ipinfo tool prefix [] [] - - Commands: - addr returns the base IP address of a prefix. - Usage: - ipinfo tool prefix addr - - Examples: - # CIDR Valid Examples. - $ ipinfo tool prefix addr 192.168.0.0/16 - $ ipinfo tool prefix addr 10.0.0.0/8 - $ ipinfo tool prefix addr 2001:0db8:1234::/48 - $ ipinfo tool prefix addr 2606:2800:220:1::/64 - - # CIDR Invalid Examples. - $ ipinfo tool prefix addr 192.168.0.0/40 - $ ipinfo tool prefix addr 2001:0db8:1234::/129 - - - bits returns the length of a prefix and reports -1 if invalid. - Usage: - ipinfo tool prefix bits - - Examples: - # CIDR Valid Examples. - $ ipinfo tool prefix bits 192.168.0.0/16 - $ ipinfo tool prefix bits 10.0.0.0/8 - $ ipinfo tool prefix bits 2001:0db8:1234::/48 - $ ipinfo tool prefix bits 2606:2800:220:1::/64 - - # CIDR Invalid Examples. - $ ipinfo tool prefix bits 192.168.0.0/40 - $ ipinfo tool prefix bits 2001:0db8:1234::/129 - - - masked returns canonical form of a prefix, masking off non-high bits, and returns the zero if invalid. - Usage: - ipinfo tool prefix masked - - Examples: - # CIDR Valid Examples. - $ ipinfo tool prefix masked 192.168.0.0/16 - $ ipinfo tool prefix masked 10.0.0.0/8 - $ ipinfo tool prefix masked 2001:0db8:1234::/48 - $ ipinfo tool prefix masked 2606:2800:220:1::/64 - - # CIDR Invalid Examples. - $ ipinfo tool prefix masked 192.168.0.0/40 - $ ipinfo tool prefix masked 2001:0db8:1234::/129 - - - is_valid reports whether a prefix is valid. - Usage: - ipinfo tool prefix is_valid - - Examples: - # CIDR Valid Examples. - $ ipinfo tool prefix is_valid 192.168.0.0/16 - $ ipinfo tool prefix is_valid 10.0.0.0/8 - $ ipinfo tool prefix is_valid 2001:0db8:1234::/48 - $ ipinfo tool prefix is_valid 2606:2800:220:1::/64 - - # CIDR Invalid Examples. - $ ipinfo tool prefix is_valid 192.168.0.0/40 - $ ipinfo tool prefix is_valid 2001:0db8:1234::/129 - - is_loopback reports whether an IP is a valid loopback address. - Usage: - ipinfo tool is_loopback [] - - Examples: - $ ipinfo tool is_loopback 127.0.0.0 - $ ipinfo tool is_loopback 160.0.0.0 - $ ipinfo tool is_loopback ::1 - $ ipinfo tool is_loopback fe08::2 - - # Check CIDR. - $ ipinfo tool is_loopback 127.0.0.0/32 - $ ipinfo tool is_loopback 128.0.0.0/32 - $ ipinfo tool is_loopback ::1/128 - $ ipinfo tool is_loopback fe08::2/64 - - # Check IP range. - $ ipinfo tool is_loopback 127.0.0.1-127.20.1.244 - $ ipinfo tool is_loopback 128.0.0.1-128.30.1.125 - - # Check for file. - $ ipinfo tool is_loopback /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_loopback - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_multicast reports whether an IP is a valid multicast address. - Usage: - ipinfo tool is_multicast [] - - Examples: - $ ipinfo tool is_multicast 239.0.0.0 - $ ipinfo tool is_multicast 127.0.0.0 - $ ipinfo tool is_multicast ff00:: - $ ipinfo tool is_multicast ::1 - - # Check CIDR. - $ ipinfo tool is_multicast 239.0.0.0/32 - $ ipinfo tool is_multicast 139.0.0.0/32 - $ ipinfo tool is_multicast ff00::1/64 - $ ipinfo tool is_multicast ::1/64 - - # Check IP range. - $ ipinfo tool is_multicast 239.0.0.0-239.255.255.1 - $ ipinfo tool is_multicast 240.0.0.0-240.255.255.1 - $ ipinfo tool is_multicast ff00::1-ff00::ffff - $ ipinfo tool is_multicast ::1-::ffff - - # Check for file. - $ ipinfo tool is_multicast /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_multicast - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_unspecified reports whether an IP is an unspecified address. - Usage: - ipinfo tool is_unspecified [] - - Examples: - $ ipinfo tool is_unspecified 0.0.0.0 - $ ipinfo tool is_unspecified 124.198.16.8 - $ ipinfo tool is_unspecified :: - $ ipinfo tool is_unspecified fe08::1 - - # Check for file. - $ ipinfo tool is_unspecified /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_unspecified - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_global_unicast reports whether an IP is a global unicast address. - Usage: - ipinfo tool is_global_unicast [] - - Examples: - $ ipinfo tool is_global_unicast 10.255.0.0 - $ ipinfo tool is_global_unicast 255.255.255.255 - $ ipinfo tool is_global_unicast 2000::1 - $ ipinfo tool is_global_unicast ff00::1 - - # Check CIDR. - $ ipinfo tool is_global_unicast 10.255.0.0/32 - $ ipinfo tool is_global_unicast 255.255.255.255/32 - $ ipinfo tool is_global_unicast 2000::1/64 - $ ipinfo tool is_global_unicast ff00::1/64 - - # Check IP range. - $ ipinfo tool is_global_unicast 10.0.0.1-10.8.95.6 - $ ipinfo tool is_global_unicast 0.0.0.0-0.255.95.6 - $ ipinfo tool is_global_unicast 2000::1-2000::ffff - $ ipinfo tool is_global_unicast ff00::1-ff00::ffff - - # Check for file. - $ ipinfo tool is_global_unicast /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_global_unicast - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_link_local_unicast reports whether IP is a link local unicast. - Usage: - ipinfo tool is_link_local_unicast [] - - Examples: - $ ipinfo tool is_link_local_unicast 169.254.0.0 - $ ipinfo tool is_link_local_unicast 127.0.0.0 - $ ipinfo tool is_link_local_unicast fe80::1 - $ ipinfo tool is_link_local_unicast ::1 - - # Check CIDR. - $ ipinfo tool is_link_local_unicast 169.254.0.0/32 - $ ipinfo tool is_link_local_unicast 139.0.0.0/32 - $ ipinfo tool is_link_local_unicast fe80::1/64 - $ ipinfo tool is_link_local_unicast ::1/64 - - # Check IP range. - $ ipinfo tool is_link_local_unicast 169.254.0.0-169.254.255.1 - $ ipinfo tool is_link_local_unicast 240.0.0.0-240.255.255.1 - $ ipinfo tool is_link_local_unicast fe80::1-feb0::1 - $ ipinfo tool is_link_local_unicast ::1-::ffff - - # Check for file. - $ ipinfo tool is_link_local_unicast /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_link_local_unicast - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_link_local_multicast reports whether IP is a link local multicast address. - Usage: - ipinfo tool is_link_local_multicast [] - - Examples: - $ ipinfo tool is_link_local_multicast 224.0.0.0 - $ ipinfo tool is_link_local_multicast 169.200.0.0 - $ ipinfo tool is_link_local_multicast ff02::2 - $ ipinfo tool is_link_local_multicast fe80:: - - # Check CIDR. - $ ipinfo tool is_link_local_multicast 224.0.0.0/32 - $ ipinfo tool is_link_local_multicast 169.200.0.0/32 - $ ipinfo tool is_link_local_multicast ff02::1/64 - $ ipinfo tool is_link_local_multicast fe80::1/64 - - # Check IP range. - $ ipinfo tool is_link_local_multicast 224.0.0.1-224.255.255.255 - $ ipinfo tool is_link_local_multicast 169.254.0.1-169.254.255.0 - $ ipinfo tool is_link_local_multicast ff02::1-ff02::ffff - $ ipinfo tool is_link_local_multicast fe80::1-fe80::ffff - - # Check for file. - $ ipinfo tool is_link_local_multicast /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_link_local_multicast - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - is_interface_local_multicast reports whether IP is an interface local multicast. - Usage: - ipinfo tool is_interface_local_multicast [] - - Examples: - $ ipinfo tool is_interface_local_multicast ff01::1 - $ ipinfo tool is_interface_local_multicast ::1 - - # Check CIDR. - $ ipinfo tool is_interface_local_multicast ff01::ffff/32 - $ ipinfo tool is_interface_local_multicast ff03::ffff/32 - - # Check IP range. - $ ipinfo tool is_interface_local_multicast ff01::1-ff01:ffff::1 - $ ipinfo tool is_interface_local_multicast ff03::1-ff03:ffff::1 - - # Check for file. - $ ipinfo tool is_interface_local_multicast /path/to/file.txt - - # Check entries from stdin. - $ cat /path/to/file1.txt | ipinfo tool is_interface_local_multicast - - Options: - --quiet, -q - quiet mode; suppress additional output. - - - Examples: - ipinfo tool - - - ipinfo download Download free ipinfo database files. - Usage: - ipinfo download [] [] - - Examples: - # Download country database in csv format. - $ ipinfo download country -f csv > country.csv - $ ipinfo download country-asn country_asn.mmdb - - Databases: - asn free ipinfo asn database. - country free ipinfo country database. - country-asn free ipinfo country-asn database. - - Options: - --token , -t - use as API token. - - Outputs: - --compress, -c - save the file in compressed format. - default: false. - --format, -f - output format of the database file. - default: mmdb. - - - ipinfo cache Manage the cache. - Usage: - ipinfo cache [] [clear] - - Examples: - # Clear all data currently in the cache. - $ ipinfo cache clear - - - ipinfo config Manage the configuration. - Usage: - ipinfo config [=...] - - Examples: - $ ipinfo config cache=disable - $ ipinfo config token=testtoken cache=enable - - Configurations: - cache= - Control whether the cache is enabled or disabled. - open_browser= - Control whether the links should open the browser or not. - token= - Save a token for use when querying the API. - (Token will not be validated). - - - ipinfo quota Print the request quota of your account. - Usage: - ipinfo quota [] - - Options: - --detailed, -d - show a detailed view of all available limits. - default: false. - - - ipinfo init Login or signup for an account. - Usage: - ipinfo init [] [] - - - Examples: - # Login command with token flag. - $ ipinfo init --token - - # Authentication without token flag. - $ ipinfo init - - Options: - --token , -t - token to login with. - (this is potentially unsafe; let the CLI prompt you instead). - --no-check - disable checking if the token is valid or not. - default: false. - - - ipinfo logout Delete your current API token session. - Usage: - ipinfo logout - - - ipinfo completion Install or output shell auto-completion script. - Usage: - ipinfo completion [] [install | bash | zsh | fish] - - Description: - Install or print out the code needed to do shell auto-completion. - - The current explicitly supported shells are: - - bash - - zsh - - fish - - Examples: - # Attempt auto-installation on any of the supported shells. - $ ipinfo completion install - - # Output auto-completion script for bash for manual installation. - $ ipinfo completion bash - - # Output auto-completion script for zsh for manual installation. - $ ipinfo completion zsh - - # Output auto-completion script for fish for manual installation. - $ ipinfo completion fish - - - ipinfo version Show the current version. - Examples: - ipinfo version - + look up details for an IP address, e.g. 8.8.8.8. + look up details for an ASN, e.g. AS123 or as123. + myip get details for your IP. + bulk get details for multiple IPs in bulk. + asn tools related to ASNs. + summarize get summarized data for a group of IPs. + map open a URL to a map showing the locations of a group of IPs. + prips print IP list from CIDR or range. + grepip grep for IPs matching criteria from any source. + matchip print the overlapping IPs and subnets. + grepdomain grep for domains matching criteria from any source. + cidr2range convert CIDRs to IP ranges. + cidr2ip convert CIDRs to individual IPs within those CIDRs. + range2cidr convert IP ranges to CIDRs. + range2ip convert IP ranges to individual IPs within those ranges. + randip Generates random IPs. + splitcidr splits a larger CIDR into smaller CIDRs. + mmdb read, import and export mmdb files. + calc evaluates a mathematical expression that may contain IP addresses. + tool misc. tools related to IPs, IP ranges and CIDRs. + download download free ipinfo database files. + cache manage the cache. + config manage the config. + quota print the request quota of your account. + init login or signup account. + logout delete your current API token session. + completion install or output shell auto-completion script. + version show current version. Options: - --token Use as the API token. - --nocache Do not use the cache. - --version Show the version number. - --help, -h Show this help message. - --pretty, -p Output pretty format.` + General: + --token , -t + use as API token. + --nocache + do not use the cache. + --version, -v + show binary release number. + --help, -h + show help. + + Outputs: + --field , -f + lookup only specific fields in the output. + field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. + multiple field names must be separated by commas. + --nocolor + disable colored output. + + Formats: + --pretty, -p + output pretty format. + --json, -j + output JSON format. + --csv, -c + output CSV format. + --yaml, -y + output YAML format.` diff --git a/lib/help_detailed.go b/lib/help_detailed.go index 34475373..236d10ae 100644 --- a/lib/help_detailed.go +++ b/lib/help_detailed.go @@ -15,14 +15,16 @@ func HelpDetailed(detailedHelp string, printHelpDefault func()) error { } cmd := exec.Command(pagerCmd) + // This allows the string to be treated as an input for the command reader := io.Reader(strings.NewReader(detailedHelp)) cmd.Stdin = reader cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - //if an error occurs running the pager, display the default help + // If an error occurs running the pager, display the default help if err := cmd.Run(); err != nil { printHelpDefault() } + return nil } diff --git a/scripts/build-archive-all.sh b/scripts/build-archive-all.sh index 4a6258c8..f2ecc970 100755 --- a/scripts/build-archive-all.sh +++ b/scripts/build-archive-all.sh @@ -44,5 +44,4 @@ cd .. rm -rf $ROOT/${CLI}/dist/usr mkdir -p $ROOT/${CLI}/dist/usr/local/bin cp $ROOT/build/${CLI}_${VSN}_linux_amd64 $ROOT/${CLI}/dist/usr/local/bin/${CLI} - -dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb \ No newline at end of file +dpkg-deb -Zgzip --build ${ROOT}/${CLI}/dist build/${CLI}_${VSN}.deb From ea1a6ed2d471d1a0850f28a59858b1de5f73e60a Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Thu, 14 Dec 2023 09:28:11 +0500 Subject: [PATCH 09/10] incorporated the suggest change --- ipinfo/detailed_help.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ipinfo/detailed_help.go b/ipinfo/detailed_help.go index 55ccce23..9b093874 100644 --- a/ipinfo/detailed_help.go +++ b/ipinfo/detailed_help.go @@ -1,6 +1,8 @@ package main -var DetailedHelp = `Usage: ipinfo [] [] +import "fmt" + +var DetailedHelp = fmt.Sprintf(`Usage: %s [] [] Commands: look up details for an IP address, e.g. 8.8.8.8. @@ -21,7 +23,7 @@ Commands: randip Generates random IPs. splitcidr splits a larger CIDR into smaller CIDRs. mmdb read, import and export mmdb files. - calc evaluates a mathematical expression that may contain IP addresses. + calc evaluates a mathematical expression that may contain IP addresses. tool misc. tools related to IPs, IP ranges and CIDRs. download download free ipinfo database files. cache manage the cache. @@ -59,4 +61,5 @@ Options: --csv, -c output CSV format. --yaml, -y - output YAML format.` + output YAML format. +`, progBase) From 9c328c6b13ca1d84e8eaed113f11b1896eb8dfea Mon Sep 17 00:00:00 2001 From: Taimoor Ali Date: Thu, 14 Dec 2023 16:58:48 +0500 Subject: [PATCH 10/10] some fixes --- ipinfo/cmd_default.go | 64 +++++++++++++++++++++++++++++++++++++++- ipinfo/detailed_help.go | 65 ----------------------------------------- lib/help_detailed.go | 1 - 3 files changed, 63 insertions(+), 67 deletions(-) delete mode 100644 ipinfo/detailed_help.go diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index 52d5a224..887868ac 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -77,6 +77,68 @@ Options: `, progBase) } +var detailedHelp = fmt.Sprintf(`Usage: %s [] [] + +Commands: + look up details for an IP address, e.g. 8.8.8.8. + look up details for an ASN, e.g. AS123 or as123. + myip get details for your IP. + bulk get details for multiple IPs in bulk. + asn tools related to ASNs. + summarize get summarized data for a group of IPs. + map open a URL to a map showing the locations of a group of IPs. + prips print IP list from CIDR or range. + grepip grep for IPs matching criteria from any source. + matchip print the overlapping IPs and subnets. + grepdomain grep for domains matching criteria from any source. + cidr2range convert CIDRs to IP ranges. + cidr2ip convert CIDRs to individual IPs within those CIDRs. + range2cidr convert IP ranges to CIDRs. + range2ip convert IP ranges to individual IPs within those ranges. + randip Generates random IPs. + splitcidr splits a larger CIDR into smaller CIDRs. + mmdb read, import and export mmdb files. + calc evaluates a mathematical expression that may contain IP addresses. + tool misc. tools related to IPs, IP ranges and CIDRs. + download download free ipinfo database files. + cache manage the cache. + config manage the config. + quota print the request quota of your account. + init login or signup account. + logout delete your current API token session. + completion install or output shell auto-completion script. + version show current version. + +Options: + General: + --token , -t + use as API token. + --nocache + do not use the cache. + --version, -v + show binary release number. + --help, -h + show help. + + Outputs: + --field , -f + lookup only specific fields in the output. + field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. + multiple field names must be separated by commas. + --nocolor + disable colored output. + + Formats: + --pretty, -p + output pretty format. + --json, -j + output JSON format. + --csv, -c + output CSV format. + --yaml, -y + output YAML format. +`, progBase) + func cmdDefault() (err error) { var ips []net.IP var fTok string @@ -111,7 +173,7 @@ func cmdDefault() (err error) { if fHelpDetailed { // Read the string and display it using a pager - lib.HelpDetailed(DetailedHelp, printHelpDefault) + lib.HelpDetailed(detailedHelp, printHelpDefault) return nil } diff --git a/ipinfo/detailed_help.go b/ipinfo/detailed_help.go deleted file mode 100644 index 9b093874..00000000 --- a/ipinfo/detailed_help.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import "fmt" - -var DetailedHelp = fmt.Sprintf(`Usage: %s [] [] - -Commands: - look up details for an IP address, e.g. 8.8.8.8. - look up details for an ASN, e.g. AS123 or as123. - myip get details for your IP. - bulk get details for multiple IPs in bulk. - asn tools related to ASNs. - summarize get summarized data for a group of IPs. - map open a URL to a map showing the locations of a group of IPs. - prips print IP list from CIDR or range. - grepip grep for IPs matching criteria from any source. - matchip print the overlapping IPs and subnets. - grepdomain grep for domains matching criteria from any source. - cidr2range convert CIDRs to IP ranges. - cidr2ip convert CIDRs to individual IPs within those CIDRs. - range2cidr convert IP ranges to CIDRs. - range2ip convert IP ranges to individual IPs within those ranges. - randip Generates random IPs. - splitcidr splits a larger CIDR into smaller CIDRs. - mmdb read, import and export mmdb files. - calc evaluates a mathematical expression that may contain IP addresses. - tool misc. tools related to IPs, IP ranges and CIDRs. - download download free ipinfo database files. - cache manage the cache. - config manage the config. - quota print the request quota of your account. - init login or signup account. - logout delete your current API token session. - completion install or output shell auto-completion script. - version show current version. - -Options: - General: - --token , -t - use as API token. - --nocache - do not use the cache. - --version, -v - show binary release number. - --help, -h - show help. - - Outputs: - --field , -f - lookup only specific fields in the output. - field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. - multiple field names must be separated by commas. - --nocolor - disable colored output. - - Formats: - --pretty, -p - output pretty format. - --json, -j - output JSON format. - --csv, -c - output CSV format. - --yaml, -y - output YAML format. -`, progBase) diff --git a/lib/help_detailed.go b/lib/help_detailed.go index 236d10ae..00fb72f6 100644 --- a/lib/help_detailed.go +++ b/lib/help_detailed.go @@ -15,7 +15,6 @@ func HelpDetailed(detailedHelp string, printHelpDefault func()) error { } cmd := exec.Command(pagerCmd) - // This allows the string to be treated as an input for the command reader := io.Reader(strings.NewReader(detailedHelp)) cmd.Stdin = reader cmd.Stdout = os.Stdout