|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 [email protected] |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package ips |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/spf13/cobra" |
| 23 | +) |
| 24 | + |
| 25 | +func init() { |
| 26 | + rootCmd.AddCommand(mdnsCmd) |
| 27 | + |
| 28 | + // mdns |
| 29 | + mdnsCmd.Flags().StringVarP(&dnsClientNet, "net", "", "udp", "Specifies the network protocol to be used by the DNS client. tcp, udp, tcp-tls.") |
| 30 | + mdnsCmd.Flags().IntVarP(&dnsClientTimeoutMs, "client-timeout", "", 1000, "Defines the timeout in milliseconds for DNS client requests.") |
| 31 | + mdnsCmd.Flags().BoolVarP(&dnsClientSingleInflight, "single-inflight", "", false, "Indicates whether the DNS client should avoid making duplicate queries concurrently.") |
| 32 | + mdnsCmd.Flags().IntVarP(&mdnsTimeoutS, "timeout", "", 20, "Specifies the timeout in seconds for MDNS operations.") |
| 33 | + mdnsCmd.Flags().StringVarP(&mdnsExchangeAddress, "exchange-address", "", "119.29.29.29", "Defines the address of the DNS server to be used for MDNS queries.") |
| 34 | + mdnsCmd.Flags().IntVarP(&mdnsRetryTimes, "retry-times", "", 3, "Sets the number of times an MDNS query should be retried on failure.") |
| 35 | + |
| 36 | + // operate |
| 37 | + mdnsCmd.Flags().StringVarP(&fields, "fields", "f", "", UsageFields) |
| 38 | + mdnsCmd.Flags().BoolVarP(&useDBFields, "use-db-fields", "", false, UsageUseDBFields) |
| 39 | + mdnsCmd.Flags().StringVarP(&rewriteFiles, "rewrite-files", "r", "", UsageRewriteFiles) |
| 40 | + mdnsCmd.Flags().StringVarP(&lang, "lang", "", "", UsageLang) |
| 41 | + |
| 42 | + // database |
| 43 | + mdnsCmd.Flags().StringSliceVarP(&rootFile, "file", "i", nil, UsageQueryFile) |
| 44 | + mdnsCmd.Flags().StringSliceVarP(&rootFormat, "format", "", nil, UsageQueryFormat) |
| 45 | + mdnsCmd.Flags().StringSliceVarP(&rootIPv4File, "ipv4-file", "", nil, UsageQueryIPv4File) |
| 46 | + mdnsCmd.Flags().StringSliceVarP(&rootIPv4Format, "ipv4-format", "", nil, UsageQueryIPv4Format) |
| 47 | + mdnsCmd.Flags().StringSliceVarP(&rootIPv6File, "ipv6-file", "", nil, UsageQueryIPv6File) |
| 48 | + mdnsCmd.Flags().StringSliceVarP(&rootIPv6Format, "ipv6-format", "", nil, UsageQueryIPv6Format) |
| 49 | + mdnsCmd.Flags().StringVarP(&readerOption, "database-option", "", "", UsageReaderOption) |
| 50 | + mdnsCmd.Flags().StringVarP(&hybridMode, "hybrid-mode", "", "aggregation", UsageHybridMode) |
| 51 | + |
| 52 | + // output |
| 53 | + mdnsCmd.Flags().StringVarP(&rootTextValuesSep, "text-values-sep", "", "", UsageTextValuesSep) |
| 54 | +} |
| 55 | + |
| 56 | +var mdnsCmd = &cobra.Command{ |
| 57 | + Use: "mdns <domain>", |
| 58 | + Short: "Execute Multi-Geolocation DNS queries.", |
| 59 | + Long: `The 'ips mdns' command is designed to query domain name resolutions across multiple regions. |
| 60 | +
|
| 61 | +Utilizing EDNS capabilities, this command sends the client's IP address to the DNS server, which then returns the domain name resolution results for the corresponding region. |
| 62 | +
|
| 63 | +The command provides a global perspective on domain name resolutions, enabling users to quickly identify any anomalies in DNS resolutions. |
| 64 | +
|
| 65 | +For more detailed information and advanced configuration options, please refer to https://github.com/sjzar/ips/blob/main/docs/mdns.md`, |
| 66 | + PreRun: PreRunInit, |
| 67 | + Run: MDNS, |
| 68 | +} |
| 69 | + |
| 70 | +func MDNS(cmd *cobra.Command, args []string) { |
| 71 | + |
| 72 | + if len(args) == 0 { |
| 73 | + _ = cmd.Help() |
| 74 | + return |
| 75 | + } |
| 76 | + |
| 77 | + ret, err := manager.MDNSResolve(args[0]) |
| 78 | + if err != nil { |
| 79 | + return |
| 80 | + } |
| 81 | + fmt.Println(ret) |
| 82 | +} |
0 commit comments