DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Show IP Address from domain name  (Read 13,172 times)

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 26
Show IP Address from domain name
« on: October 15, 2020, 02:51 AM »
Before I ask anyone to do any coding, does anyone know of a utility that allows a (list of ?) domain name(s) to be used, and the current IP Addresses that each resolves to ?

The scenario is that a game I play does have Connect by IP (only). It used to allow putting a domain name in and it all worked well, until the ability to connect via a domain name was removed.

Because the game server is behind a dynamic IP, which changes more frequently than I'd like, everyone else that plays on the server needs to open a command prompt and issue a ping request to see what the IP Address may have changed to, so they can enter that in the Connect by IP field. A number of these players haven't even heard of a command prompt nor should I need to teach them the arcane art of pinging something.

I'd like the simplest method possible, to have a portable utility (maybe C# ?) that may only have a single saved domain name, that shows the current IP of that domain name.
I can see that this would be useful for more than 1 domain name but for now, 1's all we need. Probably need a Refresh so that a timed check (every x minutes) can be overridden and have it checked immediately.

I've actually done a bit of hunting on the net and there's any manner of dns and hostname and domain name checkers but even if they work they often have screeds of other bumpf that just isn't relevant.

Anyone got any bright idea's / suggestions ?

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Show IP Address from domain name
« Reply #1 on: October 15, 2020, 07:17 AM »
test.txt
Code: (text)
google.com
cloudflare.com
microsoft.com
georgebloggs.org

Code: (text)
C:\> for /f %a in (test.txt) do ping -n 1 %a

Result:
Code: (text)
C:\>ping -n 1 google.com

Pinging google.com [216.58.200.110] with 32 bytes of data:
General failure.

Ping statistics for 216.58.200.110:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

C:\>ping -n 1 cloudflare.com

Pinging cloudflare.com [104.17.176.85] with 32 bytes of data:
General failure.

Ping statistics for 104.17.176.85:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

C:\>ping -n 1 microsoft.com

Pinging microsoft.com [13.77.161.179] with 32 bytes of data:
General failure.

Ping statistics for 13.77.161.179:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

C:\>ping -n 1 georgebloggs.org
Ping request could not find host georgebloggs.org. Please check the name and try again.

If you want to get fancy you could parse the reply for the IP only.

Or some PowerShell, this will loop every 60 seconds until it's killed:

Code: ( powershell)
$a = get-content ".\test.txt"

do {
  foreach ($i in $a ) {
    try {
      $i + " -> " + [System.Net.Dns]::GetHostAddresses($i)[0]
    }
    catch {
      $i + " -> Does not resolve"
    }
  }
  Start-Sleep -Seconds 60
} while ($true)

Result:
Code: (text)
google.com -> 216.58.200.110
cloudflare.com -> 104.17.175.85
microsoft.com -> 104.215.148.63
georgebloggs.org -> Does not resolve

You could make a simple GUI for it, (see PoshGUI), but the code will blow out past 13 lines :P
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: October 15, 2020, 09:14 AM by 4wd »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: Show IP Address from domain name
« Reply #2 on: October 15, 2020, 07:28 PM »
You could make a simple GUI for it, (see PoshGUI), but the code will blow out past 13 lines

Not if you just output it to a grid :P

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Show IP Address from domain name
« Reply #3 on: October 15, 2020, 11:26 PM »
Not if you just output it to a grid :P

True, but I was thinking of a simple updating textbox, (possibly frameless? - haven't really looked), rather than a scrolling console, (though you could clear it between updates).
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Show IP Address from domain name
« Reply #4 on: October 16, 2020, 07:08 AM »
Or by browser using any domain property listers like https://intodns.com/

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: Show IP Address from domain name
« Reply #5 on: October 16, 2020, 10:45 AM »
Dealing with varying user skill levels, having the game server host a web page that simply displayed its IP address might be the easiest way out for all.

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 26
Re: Show IP Address from domain name
« Reply #6 on: October 16, 2020, 11:18 AM »
Some good idea's here.
I'll try and follow some through.

@KodeZwerg - It seems that my domain name at No-IP is treated as a sub-domain. This is what I get "Can't get nameservers at parent server!<br>I only check domains not subdomains!"

@4wd - I like this approach and if I could parse and return just the IP and wrap the code up behind a GUI - that'd be ideal.

@Stoic Joker - that's not a bad idea to have a webpage showing the IP. The server does respond so I know the routing to it is fine (just that the game instance is only allowing IP not domain name to access the process). Still interested in having a small utility that can be run on a client machine as it is a dynamic IP (so the IP is available outside the server already) and although I have Respond to ICMP turned off on the router (so all actual ping responses will fail), the first line if the servers there does return an IP which can be parsed out if I can figure out how or erm someone can for me :) But I'll look into the other suggestions as well. Thanks.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: Show IP Address from domain name
« Reply #7 on: October 16, 2020, 03:02 PM »
[...] Still interested in having a small utility that can be run on a client machine as it is a dynamic IP

I'm on it! :)

DynamicIpMonitor_v0-1-0.png

Repo: https://github.com/publicdomain/dynamic-ip-monitor

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 9,827
    • Participated in NANY Challenge Eight Times
    • Cody Award
Re: Show IP Address from domain name
« Reply #8 on: October 16, 2020, 10:59 PM »
This isn't exactly what is requested, but it's a potential solution:

If you are in control of the host/server, or can influence the owner to do this, the host can sign up for a free service such as nsupdate.info/ and register a free domain such as "mycoolgameserver.nsupdate.info" and then configure the host's router or run an update client on the host which will tell NSUpdate the server's latest IP address. Then anyone else can always just type mycoolgameserver.nsupdate.info into their browser (or game) and will get redirected to the IP address of the server.

EDIT: I see now that I misunderstood. You already have a static domain name, but the IP address changes and the game only allows entering the IP address and not the domain name. Your needs are exactly opposite to my proposed solution. Sorry about that. :-[
« Last Edit: October 18, 2020, 09:49 PM by Deozaan »

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 26
Re: Show IP Address from domain name
« Reply #9 on: October 18, 2020, 07:38 PM »

I'm on it! :)

Vic, that is awesome ! Thank you.

Downloading from Github now.

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Show IP Address from domain name
« Reply #10 on: October 19, 2020, 08:38 AM »
i do not have delphi at hand, so here is code that does what you want, convert domain-name (example: google.com) into ip-adress.
unicode, ip4 & ip6 supported
Code
uses
  Winapi.Winsock2;

type
  PAddrInfo = ^TAddrInfo;
  TAddrInfo = packed record
    ai_flags: integer;
    ai_family: integer;
    ai_socktype: integer;
    ai_protocol: integer;
    ai_addrlen: NativeInt;
    ai_canonname: PCHAR;
    ai_addr: PSOCKADDR;
    ai_next: PAddrInfo;
  end;

function GetAddrInfo(const nodeName: PCHAR; const serviceName : PChar; const hints: PAddrInfo; var result: PAddrInfo): integer; stdcall; external 'ws2_32.dll' name 'GetAddrInfoW';
procedure FreeAddrInfo(const addrInfo: PAddrInfo); stdcall; external 'ws2_32.dll' name 'FreeAddrInfoW';

function ResolveIpAddress(const hostName: string; const ipv6: boolean): string;
const
  BUFFER_SIZE = 32768;
var
  data: TWSAData;
  error: integer;
  requestError: integer;
  r: PAddrInfo;
  s: string;
  hints: TAddrInfo;
  buffer: TArray<byte>;
  length: DWORD;
begin
  error:= WSAStartup(MAKEWORD(2, 2), data);
  try
    if (error = 0)  then
    begin
      r:= nil;
      try
        ZeroMemory(@hints, sizeof(TAddrInfo));
        if (ipv6) then
          hints.ai_family:= AF_INET6
        else
          hints.ai_family:= AF_INET;

        requestError:= GetAddrInfo(PCHAR(hostName), nil, @hints, r);
        if (requestError = 0) then
        begin
          length:= BUFFER_SIZE;
          SetLength(buffer, BUFFER_SIZE);
          if (WSAAddressToString(r.ai_addr^, r.ai_addrlen, nil, @buffer[0], length) = 0) then
          begin
            setLength(buffer, length * 2);
            s:= TUnicodeEncoding.Unicode.GetString(@buffer[0]);
            exit(s);
          end
          else
            exit('0.0.0.0');
        end
        else
          exit('0.0.0.0');

      finally
        FreeAddrInfo(r);
      end;
    end
  finally
    if (error = 0) then
      WSACleanup();
  end;
end;

if 0.0.0.0 is returned, there was an error

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: Show IP Address from domain name
« Reply #11 on: October 19, 2020, 07:01 PM »
Vic, that is awesome ! Thank you.
My pleasure! :) Currently adding more features toward first public release later today/tomorrow
Code
 :Thmbsup:

[attach=1]

[quote author=davcom link=topic=50589.msg441619#msg441619 date=1603049916]Downloading from Github now.[/quote]
Just pushed new code @ [iurl=https://github.com/publicdomain/dynamic-ip-monitor]GitHub repo[/iurl]. Stay tuned!
« Last Edit: October 22, 2020, 08:49 AM by publicdomain »

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 26
Re: Show IP Address from domain name
« Reply #12 on: October 19, 2020, 10:33 PM »
Definitely very tuned :)

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • Participated in NANY Challenge Four Times
    • Coding Snacks
Re: Show IP Address from domain name
« Reply #13 on: October 20, 2020, 08:25 AM »
Cool @vic, i just saw first preview image where ip was missing (reason of this topic) thats why i posted code.
Since it changed now I do not interfere with my own resolver-project anymore (works for IPv4/IPv6/DNStoIP/IPtoDNS)  :Thmbsup:

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: Show IP Address from domain name
« Reply #14 on: October 22, 2020, 10:54 AM »
Definitely very tuned :)

Thank you! Just released @ DC members space :Thmbsup:

Release: Dynamic IP Monitor v0.1.0

Cool @vic, i just saw first preview image where ip was missing (reason of this topic) thats why i posted code.

Appreciated :)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Show IP Address from domain name
« Reply #15 on: October 27, 2020, 05:38 PM »
Can I just remind people to please consider taking a moment of your time and sending a donation to the coders who hang out here who create little programs based on requests?
You have no idea how much even a small donation might mean to a coder who could use the encouragement.
Just click on the gold coin under their name to send them some of a donation you have made to the site.

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 26
Re: Show IP Address from domain name
« Reply #16 on: October 29, 2020, 11:49 AM »
Hey Jesse, Vic had 2 options for sending him something and I used Paypal not DC credits. Wasn't a huge amount but I really do appreciate what's been done and the response from everyone that chipped in with suggestions.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: Show IP Address from domain name
« Reply #17 on: October 30, 2020, 04:04 PM »
Thank you from the bottom of my heart dear Jesse and Dave :-*

I'm super-motivated & currently adding multi-domain support to v0.2 :Thmbsup:

The fellows @ DonationCoder are truly awesome!

From a much-grateful,
Vic

Original address: https://www.donationcoder.com/forum/index.php?topic=50589.0