Page 1 of 1

RvdH DNSResolver + Powershell

Posted: 2020-01-15 02:18
by palinka
Trying to figure out how to call the DNS Resolver from powershell. I'm not getting far. Here's what I have so far.

Code: Select all

$IP = '221.120.216.98'
$IPS = $IP.Split("\.")
$RevIPS = $IPS[3]+"."+$IPS[2]+"."+$IPS[1]+"."+$IPS[0]
$DNS = New-Object -ComObject DNSLibrary.DNSResolver
$PTR = $DNS.PTR("$RevIPS")
Write-Host $PTR
All I get is a blank result with no error.

By switching around a couple of things like this:

Code: Select all

$PTR = New-Object -ComObject DNSLibrary.DNSResolver.PTR("$RevIPS")
I get error:

Code: Select all

New-Object : A positional parameter cannot be found that accepts argument
'98.216.120.221'.
At C:\scripts\hmailserver\PTRTests\testpsptr.ps1:5 char:8
+ $PTR = New-Object -ComObject DNSLibrary.DNSResolver.PTR("$RevIPS")
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-Object], ParameterBinding
   Exception
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Co
   mmands.NewObjectCommand
Any ideas to get me going?

Re: RvdH DNSResolver + Powershell

Posted: 2020-01-15 06:52
by Dravion
The ip addfess is unexpected at the position.
Check Argument order.

Re: RvdH DNSResolver + Powershell

Posted: 2020-01-15 11:37
by palinka
Dravion wrote:
2020-01-15 06:52
The ip addfess is unexpected at the position.
Check Argument order.
That's the problem I'm having. I don't know the argument order nor the correct syntax.

Re: RvdH DNSResolver + Powershell

Posted: 2020-01-15 12:25
by RvdH
Do not reverse the IP, you are trying to make a PTR lookup :!:

Code: Select all

$IP = '221.120.216.98'
$DNS = New-Object -ComObject DNSLibrary.DNSResolver
$PTR = $DNS.PTR("$IP")
Write-Host $PTR

Code: Select all

lhr63.pie.net.pk

Re: RvdH DNSResolver + Powershell

Posted: 2020-01-15 14:34
by palinka
RvdH wrote:
2020-01-15 12:25
Do not reverse the IP, you are trying to make a PTR lookup :!:

Code: Select all

$IP = '221.120.216.98'
$DNS = New-Object -ComObject DNSLibrary.DNSResolver
$PTR = $DNS.PTR("$IP")
Write-Host $PTR

Code: Select all

lhr63.pie.net.pk
Thank you! I knew it was something dumb like that. I should have tried it myself before even posting. No wonder I wasn't getting an error. :oops: