|
| 1 | +using NoPowerShell.Arguments; |
| 2 | +using NoPowerShell.HelperClasses; |
| 3 | +using System.Net; |
| 4 | + |
| 5 | +/* |
| 6 | +Author: @_bitsadmin |
| 7 | +Website: https://github.com/bitsadmin |
| 8 | +License: BSD 3-Clause |
| 9 | +*/ |
| 10 | + |
| 11 | +namespace NoPowerShell.Commands |
| 12 | +{ |
| 13 | + public class ResolveDnsNameCommand : PSCommand |
| 14 | + { |
| 15 | + public ResolveDnsNameCommand(string[] userArguments) : base(userArguments, SupportedArguments) |
| 16 | + { |
| 17 | + } |
| 18 | + |
| 19 | + public override CommandResult Execute(CommandResult pipeIn) |
| 20 | + { |
| 21 | + // Obtain cmdlet parameters |
| 22 | + string query = _arguments.Get<StringArgument>("Name").Value; |
| 23 | + //string queryType = _arguments.Get<StringArgument>("Type").Value; |
| 24 | + //string server = _arguments.Get<StringArgument>("Server").Value; |
| 25 | + |
| 26 | + // Resolve and store results |
| 27 | + IPHostEntry response = Dns.GetHostEntry(query); |
| 28 | + |
| 29 | + foreach(IPAddress ip in response.AddressList) |
| 30 | + { |
| 31 | + _results.Add( |
| 32 | + new ResultRecord() |
| 33 | + { |
| 34 | + { "Name", response.HostName }, |
| 35 | + { "IPAddress", ip.ToString() } |
| 36 | + } |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + return _results; |
| 41 | + } |
| 42 | + |
| 43 | + public static new CaseInsensitiveList Aliases |
| 44 | + { |
| 45 | + get |
| 46 | + { |
| 47 | + return new CaseInsensitiveList() |
| 48 | + { |
| 49 | + "Resolve-DnsName", |
| 50 | + "nslookup", "host" // Not official |
| 51 | + }; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + public static new ArgumentList SupportedArguments |
| 56 | + { |
| 57 | + get |
| 58 | + { |
| 59 | + return new ArgumentList() |
| 60 | + { |
| 61 | + new StringArgument("Name") |
| 62 | + // TODO: |
| 63 | + //new StringArgument("Type", true), |
| 64 | + //new StringArgument("Server", true), |
| 65 | + }; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + public static new string Synopsis |
| 70 | + { |
| 71 | + get { return "This template shows how easy it is to develop new NoPowerShell cmdlets."; } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments