topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday October 22, 2020, 1:38 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Show IP Address from domain name  (Read 708 times)

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 25
    • View Profile
    • Donate to Member
Show IP Address from domain name
« on: October 14, 2020, 09:51 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,381
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #1 on: October 15, 2020, 02:17 AM »
test.txt
Code: Text [Select]
  1. google.com
  2. cloudflare.com
  3. microsoft.com
  4. georgebloggs.org

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

Result:
Code: Text [Select]
  1. C:\>ping -n 1 google.com
  2.  
  3. Pinging google.com [216.58.200.110] with 32 bytes of data:
  4. General failure.
  5.  
  6. Ping statistics for 216.58.200.110:
  7.     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  8.  
  9. C:\>ping -n 1 cloudflare.com
  10.  
  11. Pinging cloudflare.com [104.17.176.85] with 32 bytes of data:
  12. General failure.
  13.  
  14. Ping statistics for 104.17.176.85:
  15.     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  16.  
  17. C:\>ping -n 1 microsoft.com
  18.  
  19. Pinging microsoft.com [13.77.161.179] with 32 bytes of data:
  20. General failure.
  21.  
  22. Ping statistics for 13.77.161.179:
  23.     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  24.  
  25. C:\>ping -n 1 georgebloggs.org
  26. 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 [Select]
  1. $a = get-content ".\test.txt"
  2.  
  3. do {
  4.   foreach ($i in $a ) {
  5.     try {
  6.       $i + " -> " + [System.Net.Dns]::GetHostAddresses($i)[0]
  7.     }
  8.     catch {
  9.       $i + " -> Does not resolve"
  10.     }
  11.   }
  12.   Start-Sleep -Seconds 60
  13. } while ($true)

Result:
Code: Text [Select]
  1. google.com -> 216.58.200.110
  2. cloudflare.com -> 104.17.175.85
  3. microsoft.com -> 104.215.148.63
  4. 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
« Last Edit: October 15, 2020, 04:14 AM by 4wd »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 10,695
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #2 on: October 15, 2020, 02: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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,381
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #3 on: October 15, 2020, 06: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).

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 512
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #4 on: October 16, 2020, 02:08 AM »
Or by browser using any domain property listers like https://intodns.com/
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,567
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #5 on: October 16, 2020, 05: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: 25
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #6 on: October 16, 2020, 06: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: 97
  • Call me Vic!
    • View Profile
    • https://publicdomaindaily.com
    • Read more about this member.
    • Donate to Member
Re: Show IP Address from domain name
« Reply #7 on: October 16, 2020, 10:02 AM »
[...] 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/p...n/dynamic-ip-monitor
New releases: www.PublicDomainDaily.com
Extend your support: PayPal.me/victorvls || Patreon.com/publicdomain || DonationCredits
Email: publicdomainvicgmail.com

2020 Goal: Fulfilling my full-time purpose of helping the fellows & giving to the Public Domain every day!
--Victor

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,162
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #8 on: October 16, 2020, 05: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, 04:49 PM by Deozaan »

davcom

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 25
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #9 on: October 18, 2020, 02:38 PM »

I'm on it! :)


Vic, that is awesome ! Thank you.

Downloading from Github now.

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 512
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #10 on: October 19, 2020, 03: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
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
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 97
  • Call me Vic!
    • View Profile
    • https://publicdomaindaily.com
    • Read more about this member.
    • Donate to Member
Re: Show IP Address from domain name
« Reply #11 on: October 19, 2020, 02:01 PM »
Vic, that is awesome ! Thank you.
My pleasure! :) Currently adding more features toward first public release later today/tomorrow [code finished @ GitHub] :Thmbsup:

DynamicIpMonitor_v0-1-0_2020-10-19_15-05.png

Downloading from Github now.
Just pushed new code @ GitHub repo. Stay tuned!
New releases: www.PublicDomainDaily.com
Extend your support: PayPal.me/victorvls || Patreon.com/publicdomain || DonationCredits
Email: publicdomainvicgmail.com

2020 Goal: Fulfilling my full-time purpose of helping the fellows & giving to the Public Domain every day!
--Victor
« Last Edit: Today at 03:49 AM by publicdomain »

davcom

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

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 512
    • View Profile
    • Donate to Member
Re: Show IP Address from domain name
« Reply #13 on: October 20, 2020, 03: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:
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 97
  • Call me Vic!
    • View Profile
    • https://publicdomaindaily.com
    • Read more about this member.
    • Donate to Member
Re: Show IP Address from domain name
« Reply #14 on: Today at 05: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 :)
New releases: www.PublicDomainDaily.com
Extend your support: PayPal.me/victorvls || Patreon.com/publicdomain || DonationCredits
Email: publicdomainvicgmail.com

2020 Goal: Fulfilling my full-time purpose of helping the fellows & giving to the Public Domain every day!
--Victor