GetHostEntry

Started by stanl, August 10, 2020, 03:56:40 AM

Previous topic - Next topic

stanl

.... more exploring WB CLR for System.Net.Dns -  The GetHostByName method has been declared obsolete and you are encouraged to use GetHostEntry.  The script below resolves Microsoft.com to several IP addresses. However using GetHostEntry on those IP's creates a COM/CLR error. I used IntControl(73,2,0,0,0) to display the errors without the script failing. Probably using the method incorrectly so any advice is welcome:
Code (WINBATCH) Select


;GetHostEntry - failure
;==================================================================
IntControl(73,2,0,0,0)
ObjectClrOption("useany","System.Net")
oDNS = ObjectClrNew("System.Net.Dns")
oHost = ObjectClrNew("System.Net.IPHostEntry")


oAddress = oDNS.GetHostEntry("microsoft.com")
;oAddress = oDNS.GetHostByName("microsoft.com")
ip = ""
host = ""
errs = ""


BoxOpen("Testing GetHostEntry","Microsoft.com")


ForEach a in oAddress.AddressList
   cIP = a.ToString()
   BoxText("Looking for Host Name: ":cIP)
   ip = ip:cIP:@LF
   host = host:oDNS.GetHostEntry('%cIP%')
Next


BoxShut()
Message("Ip Addresses - Microsoft",ip:@LF:host:@LF:errs)


oAddress=0
oDNS=0
oHost=0


Exit


:WBERRORHANDLER
info = wberrorarray[6]
errs = errs:cIP:" ":info:@LF
IntControl(73,2,0,0,0)
Return


;==================================================================



td

If you pressed the "More Error Info" button by allowing the error to display, you would have noticed that the CLR exception reads "No such host is known" which suggests that there are not any publicly available DNS reverse lookup records for any of the MFSFT v4 IP addresses returned in the address list provided by the DNS class. On the other hand, if you use "winbatch.com" instead of "microsoft.com" you will get a number associated with each IP address in the Massage box. That number represents a handle to an IPHostEntry class object for the specified IP address.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

It seems like a remote possibility but I should have also mentioned that the "No such host is known" error could be the result of the DNS query timing out before the reverse lookup record is found even though it exists.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on August 10, 2020, 08:26:19 AM
If you pressed the "More Error Info" button by allowing the error to display, you would have noticed that the CLR exception reads "No such host is known" which suggests that there are not any publicly available DNS reverse lookup records for any of the MFSFT v4 IP addresses returned in the address list provided by the DNS class. On the other hand, if you use "winbatch.com" instead of "microsoft.com" you will get a number associated with each IP address in the Massage box. That number represents a handle to an IPHostEntry class object for the specified IP address.


The error was displayed as part of the script so no need to let it fail. I picked Microsoft because I knew it would return several IP's and the goal was to reverse DNS to return the hostname for each.


Which brings up the question of how to resolve an IPHostEntry handle to a hostname. So if I just wanted to resolve 24.113.42.123 I would get a handle 40912192 and if I ask for hostname I get 24-113-42-123.wavecable.com  [this is by running my script for "winbatch.com" and adding Hostname to line: host = host:oDNS.GetHostEntry('%cIP%').HostName].


But then if I look for wavecable.com in the script it errors out before even returning any IP addresses.








td

Quote from: stanl on August 11, 2020, 03:23:11 AM

The error was displayed as part of the script so no need to let it fail. I picked Microsoft because I knew it would return several IP's and the goal was to reverse DNS to return the hostname for each.

I noticed. I just prefer to let WinBatch report its errors unless there is a specific and anticipated error that I need to handle.

Quote
Which brings up the question of how to resolve an IPHostEntry handle to a hostname. So if I just wanted to resolve 24.113.42.123 I would get a handle 40912192 and if I ask for hostname I get 24-113-42-123.wavecable.com  [this is by running my script for "winbatch.com" and adding Hostname to line: host = host:oDNS.GetHostEntry('%cIP%').HostName].

But then if I look for wavecable.com in the script it errors out before even returning any IP addresses.

That is not at all surprising.  The rDNS standard does not require anything other than the IP address in decimal form and something. The something is usually ".in-addr.arpa" in the PTR record. So you would expect to see  "24-113-42-123.in-addr.arpa" but the trailing part could be just about anything. CNAME records and TXT records can also be used as other rDNS records.  ILC's ISP is Wave and not Wave Cable (the IP address is leased from their address block) but they apparently left the rDNS record unchanged from their early days as primarily a cable tv provider instead of a fiber-optic ISP. ILC manages the forward DNS records but not the rDNS records.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

A little out of my league, but good to know.  If I type in 24.113.42.123 in my browser it brings up winbatch. Using GetHostEntry() for the IP is pretty worthless, but using System.Net.Dns to find IP associated with host provides me a good Map.