Skip to content

Commit 136dcdf

Browse files
committed
Added Resolve-DnsName cmdlet
Added extra overload for StringArgument to simplify calling
1 parent 1988acb commit 136dcdf

8 files changed

Lines changed: 92 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ Authors of additional NoPowerShell cmdlets are added to the table below. Moreove
8989

9090
| Cmdlet | Contributed by | GitHub | Twitter |
9191
| - | - | - | - |
92-
| Resolve-DnsName | | | |
9392
| Get-ADUser | | | |
9493
| Get-ADGroupMember | | | |
9594

@@ -116,5 +115,6 @@ Authors of additional NoPowerShell cmdlets are added to the table below. Moreove
116115
| Format-Table | Utility | |
117116
| Invoke-WebRequest | Utility |
118117
| Select-Object | Utility |
118+
| Resolve-DnsName | DnsClient | Very basic implementation, support for specifying DNS server and query type need to be added |
119119

120120
**Authored by Arris Huijgen (@_bitsadmin - https://github.com/bitsadmin)**

Source/NoPowerShell/Arguments/StringArgument.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public StringArgument(string argumentName, string defaultValue, bool optionalArg
3434
this._isOptionalArgument = optionalArgument;
3535
}
3636

37+
/// <summary>
38+
/// Create a new string argument with a null default value specifying whether it is optional or not.
39+
/// </summary>
40+
/// <param name="argumentName">Name of the parameter</param>
41+
/// <param name="optionalArgument">True if the argument is optional; False if not</param>
42+
public StringArgument(string argumentName, bool optionalArgument) : this(argumentName, null, optionalArgument)
43+
{
44+
}
45+
3746
/// <summary>
3847
/// Create a new string argument with a null default value.
3948
/// </summary>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
}

Source/NoPowerShell/Commands/Management/GetWmiObjectCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public override CommandResult Execute(CommandResult pipeIn)
5151
{
5252
new StringArgument("Namespace", @"root\cimv2", true),
5353
new StringArgument("Query"),
54-
new StringArgument("Class", null, true),
55-
new StringArgument("Filter", null, true)
54+
new StringArgument("Class", true),
55+
new StringArgument("Filter", true)
5656
};
5757
}
5858
}

Source/NoPowerShell/Commands/PSCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public PSCommand(string[] userArguments, ArgumentList supportedArguments)
3333
supportedArguments.AddRange(new List<Argument>()
3434
{
3535
new StringArgument("ComputerName", ".", true),
36-
new StringArgument("Username", null, true),
37-
new StringArgument("Password", null, true)
36+
new StringArgument("Username", true),
37+
new StringArgument("Password", true)
3838
});
3939

4040
_arguments = ParseArguments(userArguments, supportedArguments);

Source/NoPowerShell/Commands/Utility/InvokeWebRequestCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public override CommandResult Execute(CommandResult pipeIn)
5555
{
5656
return new ArgumentList()
5757
{
58-
new StringArgument("URI", null),
59-
new StringArgument("OutFile", null, true)
58+
new StringArgument("URI"),
59+
new StringArgument("OutFile", true)
6060
};
6161
}
6262
}

Source/NoPowerShell/Commands/Utility/SelectObjectCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override CommandResult Execute(CommandResult pipeIn)
4848
{
4949
return new ArgumentList()
5050
{
51-
new StringArgument("Property", null)
51+
new StringArgument("Property")
5252
};
5353
}
5454
}

Source/NoPowerShell/NoPowerShell.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Compile Include="Arguments\StringArgument.cs" />
4747
<Compile Include="Commands\Additional\GetSystemInfoCommand.cs" />
4848
<Compile Include="Commands\Core\GetCommandCommand.cs" />
49+
<Compile Include="Commands\DnsClient\ResolveDnsNameCommand.cs" />
4950
<Compile Include="Commands\Management\GetItemPropertyCommand.cs" />
5051
<Compile Include="Commands\Management\RemoveItemCommand.cs" />
5152
<Compile Include="Commands\Management\InvokeWmiMethodCommand.cs" />

0 commit comments

Comments
 (0)