Subscribe
Accepted Solution

WFA Function to Reverse DNS Lookup

I have an need to be able to mount an NFS Datastore into VMWare using its DNS Name. 

 

I'm not familiar with MVEL, and there isn't much material that I can find on it.

 

Can someone assist in creating a function that returns back the DNS name when it is passed an IP address? 

 

I want to do this so that I don't have to customize the certified Mount Datastore command, and it will assist down the line with return parameters.

Re: WFA Function to Reverse DNS Lookup

Hi Corey,

 

I would recommend you do this using the "System.Net.Dns" .NET class within your WFA Command using PowerShell (IE your command would accept an IP Address as an input parameter but will perform a DNS lookup of the hostname then mount the datastore using the hostname). You could do it one line of PowerShell

 

> [String]$ipAddress = "192.168.100.10"
> [String]$hostName = [System.Net.Dns]::GetHostEntry($ipAddress).HostName

> $hostName
> TESTWFA1.testlab.local

 

Or...you could create a PowerShell function to include in your WFA Command. EG:

 

#'------------------------------------------------------------------------------
Function Get-DNSHostName{
    [CmdletBinding()]
    Param(
    [Parameter(Position=0,
       Mandatory=$True,
       ValueFromPipeLine=$True,
       ValueFromPipeLineByPropertyName=$True)]
       [String]$IPAddress
    )
    Try{
       [String]$hostName = [System.Net.Dns]::GetHostEntry($ipAddress).HostName
    }Catch{
       [String]$hostName = ""
    }
    Return $hostName;
}#End Function
#'------------------------------------------------------------------------------
[String]$ipAddress = "192.168.100.10"
[String]$hostName = Get-DNSHostName -IPAddress $ipAddress
Write-Host $hostName

 

Note: This assumes you have configured your A & PTR records in DNS.

 

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: WFA Function to Reverse DNS Lookup

Thanks Matt for the reply. I have used a similar method in non-certified commands in WFA. What I am trying to avoid is cloning the "certified" command, and making the modifications to it. 

 

In my example I'm wanting to use the certified command "Create VMware NFS Datastore".  So what I was looking to do was use the function capability inside WFA (not powershell functions), and feed the ip address to the function outside of the command to feed to the certified command.

Re: WFA Function to Reverse DNS Lookup

WFA MVEL fucntions are java functions. You can do anything with a Java code, you can create a function and do it. For the Reverse DNS lookup, the following function will do.

===

function reverseDns(ip)
{
import java.net.*;

InetAddress add = InetAddress.getByName(ip);
String hostfqdn = add.getCanonicalHostName();
return hostfqdn;


}

===

 

Now you can use it in your workflow and get the DNS names.

 

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: WFA Function to Reverse DNS Lookup

That's exactly what I'm looking for!

 

One day I will learn java syntax. Smiley Happy