1. Sivaprakash BKR
  2. PowerBuilder
  3. Monday, 10 January 2022 06:23 AM UTC

Hello,

PB 2019 R3

Want to display hostname given an IPv4 address.  Got a list of IPv4 address for which I need to display the corresponding hostname (computername) in an PB application. 

IPv4 address
192.168.1.10
192.168.1.20
10.0.0.200
...

I need to display the hostname for all the above IPv4 address.   Any function available?

Happiness Always
BKR Sivaprakash

 

Accepted Answer
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Monday, 17 January 2022 08:19 AM UTC
  2. PowerBuilder
  3. # Permalink

As Roland has updated his winsock utility, I mark this issue as resolved.

Thanks Roland.

 

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 10 January 2022 14:47 PM UTC
  2. PowerBuilder
  3. # 1

Is your database server running on the IP address?

If so, depending on which database you are running, you could get the hostname by running some stored procedure or function on the server.

From the client you then query that table.

regards

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 10 January 2022 13:38 PM UTC
  2. PowerBuilder
  3. # 2

My Winsock example has a function of_GetIPAddress that returns a string array of IP Addresses for a hostname.

https://www.topwizprogramming.com/freecode_winsock.html

 

Comment
  1. Miguel Leeuwe
  2. Monday, 10 January 2022 14:09 PM UTC
Hi Roland,

I think he wants it reversed: get the hostname from an ip4 address.

regards
  1. Helpful
  1. Sivaprakash BKR
  2. Wednesday, 12 January 2022 06:04 AM UTC
Roland

Miguel is correct. I tried Winsock utility, as Miguel says the requirement is to be other way.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 10 January 2022 08:07 AM UTC
  2. PowerBuilder
  3. # 3

You could use a powershell script like this one:

$ipAddress= "8.8.8.8"
[System.Net.Dns]::GetHostByAddress($ipAddress).Hostname

result: dns.google

or do a

"ping -a 8.8.8.8"

or a

"nslookup host 8.8.8.8"

but all of these are inferior solutions of using some APIs from the winsock libraries. Roland has an example on his topwizprogramming site, but it's embedded in PBNI and the actual calls are in a C++ solution. It goes way over my head.

regards

MiguelL

Comment
  1. Roland Smith
  2. Monday, 10 January 2022 14:25 PM UTC
I have pure PB code Winsock also which is the one I linked above. I don't know how to do a DNS lookup from API functions. The PB app could use my RunAndWait object to run nslookup and redirect the output to a file. It could then read the file.
  1. Helpful 1
  1. Miguel Leeuwe
  2. Monday, 10 January 2022 14:31 PM UTC
Aha! I was looking at the wrong winsock: https://www.topwizprogramming.com/downloads/WinsockPBNI.zip that C++ solution does seem to contain some kind of a getHostName function if I remember well (not sure about the name).
  1. Helpful 1
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 10 January 2022 08:05 AM UTC
  2. PowerBuilder
  3. # 4

Maybe Windows API functions GetNameInfoW will help.

But I have no example how to use it. Sorry.

Comment
  1. Roland Smith
  2. Wednesday, 12 January 2022 19:02 PM UTC
I updated my Winsock example. It now has a function of_GetNameInfo which returns HostName for the given IP Address.

https://www.topwizprogramming.com/freecode_winsock.html

  1. Helpful 6
  1. Miguel Leeuwe
  2. Wednesday, 12 January 2022 23:15 PM UTC
Very useful to any of us. Thank you Roland!
  1. Helpful
  1. Sivaprakash BKR
  2. Thursday, 13 January 2022 12:43 PM UTC
Thanks Roland, will add into my library list.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.