Data On Demand Unix resolve address probe action

Community.DataOnDemand.Unix.Probe.ResolveAddress (ProbeActionModuleType)

Resolves the listed IP addresses or names on the target computer.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeMicrosoft.SystemCenter.WSManagement.WSManData

Member Modules:

ID Module Type TypeId RunAs 
PassThru ProbeAction System.PassThroughProbe Default
Probe ProbeAction Microsoft.Unix.WSMan.Invoke.ProbeAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Addressesstring$Config/Addresses$AddressesIP addresses or names to resolve, as a comma seperated list.
Formatstring$Config/Format$FormatOutput format. Allowed values: csv, csvEx
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (seconds)Script timeout in seconds

Source Code:

<ProbeActionModuleType ID="Community.DataOnDemand.Unix.Probe.ResolveAddress" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Addresses" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Format" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="csv"/>
<xsd:enumeration value="csvEx"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetSystem" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Addresses" Selector="$Config/Addresses$" ParameterType="string"/>
<OverrideableParameter ID="Format" Selector="$Config/Format$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<ProbeAction ID="PassThru" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Probe" TypeID="MUL!Microsoft.Unix.WSMan.Invoke.ProbeAction">
<TargetSystem>$Config/TargetSystem$</TargetSystem>
<Uri>http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem?__cimnamespace=root/scx</Uri>
<Selector/>
<InvokeAction>ExecuteScript</InvokeAction>
<Input>
&lt;p:ExecuteScript_INPUT xmlns:p="http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem"&gt;
&lt;p:script&gt;#!/usr/bin/perl -w
# Provides Provides name/IpAddress information in a format expected by Squared Up's Visual Application Discovery and Analysis feature.
# Copyright 2016 Squared Up Limited, All Rights Reserved.

use strict;
use warnings;
use Socket;

# Handle arguments and global vars
my $format = "csv";
my $lineEnd;
my @queries;

if ( $#ARGV &amp;lt; 0 || $#ARGV &amp;gt; 1 ) {
print "Usage: $0 [format] nameOrIp\n";
exit(1);
}
elsif ($#ARGV == 0) {
@queries = split(/\s*,\s*/, $ARGV[0]);
}
elsif ($#ARGV == 1) {
$format = $ARGV[0];
@queries = split(/\s*,\s*/, $ARGV[1]);
}

# Set output format
if ($format eq "csv") {
$lineEnd = "\n";
}
elsif ($format eq "csvEx") {
$lineEnd = "\%EOL\%"
}
else {
print "Unknown format '$format'\n";
exit(1);
}

# Although Socket could be used instead of regex and manual validation, the behaviour and availability is not platform consistent.
sub _is_ipv4 {
shift if ref $_[0];
my $value = shift;

return undef unless defined($value);

# Capture each octet using a regex, so we can examine their range
my (@octets) = $value =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
return undef unless (@octets == 4);
foreach (@octets) {
# False if octet is outside range 0-255 or has a leading 0s (e.g 010 )
return undef if $_ &amp;lt; 0 || $_ &amp;gt; 255;
return undef if $_ =~ /^0\d{1,2}$/;
}
return join('.', @octets);
}

# Print Header
print "IpAddress,HostName$lineEnd";

# Process queries based on query type (A or PTR)
foreach my $query (@queries) {
if (_is_ipv4($query)) {
# PTR Record lookup
my $hostname = gethostbyaddr(inet_aton($query), AF_INET);
if ($hostname){
print "$query,$hostname$lineEnd";
}
}
else {
# A Record lookup, returning first address only
my @result = gethostbyname($query);
if (@result) {
my $ipaddr = inet_ntoa($result[4]);
print "$ipaddr,$query$lineEnd";
}
}
}

exit(0);
&lt;/p:script&gt;
&lt;p:arguments&gt;$Config/Format$ "$Config/Addresses$"&lt;/p:arguments&gt;
&lt;p:timeout&gt;$Config/TimeoutSeconds$&lt;/p:timeout&gt;
&lt;/p:ExecuteScript_INPUT&gt;
</Input>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Probe">
<Node ID="PassThru"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>MSWL!Microsoft.SystemCenter.WSManagement.WSManData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>