RvdH DNSResolver + Powershell

Forum for things that doesn't really have anything to do with hMailServer. Such as php.ini, beer, etc etc.
Post Reply
palinka
Senior user
Senior user
Posts: 1542
Joined: 2017-09-12 17:57

RvdH DNSResolver + Powershell

Post by palinka » 2020-01-15 02:18

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?

User avatar
Dravion
Senior user
Senior user
Posts: 1611
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: RvdH DNSResolver + Powershell

Post by Dravion » 2020-01-15 06:52

The ip addfess is unexpected at the position.
Check Argument order.

palinka
Senior user
Senior user
Posts: 1542
Joined: 2017-09-12 17:57

Re: RvdH DNSResolver + Powershell

Post by palinka » 2020-01-15 11:37

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.

User avatar
RvdH
Senior user
Senior user
Posts: 843
Joined: 2008-06-27 14:42
Location: Netherlands

Re: RvdH DNSResolver + Powershell

Post by RvdH » 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
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

palinka
Senior user
Senior user
Posts: 1542
Joined: 2017-09-12 17:57

Re: RvdH DNSResolver + Powershell

Post by palinka » 2020-01-15 14:34

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:

Post Reply