Posted: 5th Jul 2021 0:32
Anyway to resolve an url to IP Address in agk??
Posted: 5th Jul 2021 1:11
You may want to make a http request to an official dns service.


Or you can directly use a tcp socket, if you want to do it bare-bone:
http://serverfault.com/questions/173187/what-does-a-dns-request-look-like

Or you use the runapp feature, start a batch file with:
+ Code Snippet
nslookup www.google.com 


is run and the result will be printed to a file, that you can parse the ip.
Posted: 9th Jul 2021 8:49
What purpose you want this ?
Like I have a game and server hosted on amazon ec2 . and I don't use static ip . so their I install noIp service its free . they give me some url and I use

http = CreateHTTPConnection()
SetHTTPHost( http, "the url here ", 0 )

and its get me to the IP address .
Posted: 9th Jul 2021 20:08
Like I have a game and server hosted on amazon ec2

I'm sure a lot of people would be interested (Me included) in how you set that up and implemented it.
Posted: 17th Jul 2021 3:09
What purpose you want this ?

A player hosting my game's server wants his players to connect to his server with a url instead of having to type out an IP address.
Posted: 17th Jul 2021 17:51
@BlinkOK . if you use SetHTTPHost( http, "www.appgamekit.com", 0 ) , this " appgamekit.com " actually return a IP address . or even you use commend for Multiplayer Games ( HostNetwork or JoinNetwork) you need to put IP address . so in my AWS EC2 I have a IP address but it change upon restart or or for some others reason because I am not using static or elastic IP address . So I use https://www.noip.com/ setvice it's free for 3 custom url . you need to install small software and its track your pc/AWS ec2 ip address every 5 minuets . I hope you understand but still If you are not clear then tell me I try to make a YouTube video but my English not good .
Posted: 17th Jul 2021 20:20
Thanks you Mr Bam!
Posted: 18th Jul 2021 3:04
@tambam, making sure that you're talking about a need for additional software to return the IP address, correct? otherwise, i don't see the solution in what you offer.

meanwhile:
You may want to make a http request to an official dns service.

this returns the IP via DNS lookup (@ google) but it's not perfect where it doesn't account for errors:
+ Code Snippet
// Project: DNS Lookup 
// Created: 2021-07-16
// By: Virtual Nomad
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "DNS Lookup" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )

// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 ) 

URL$ = "google.com"
IP$ = Lookup(URL$)

do

    If GetRawKeyState(27) then End    

    Print( IP$ )
    Sync()
loop

Function Lookup(URL$)
	http = CreateHTTPConnection()
	SetHTTPHost( http, "dns.google", 1 )
	SendHTTPRequestASync( http, "/resolve?name="+URL$+"&type=A")

	while GetHTTPResponseReady(http) = 0
		Print( "Connecting..." )
		Sync()
	endwhile
	
	response$ = GetHTTPResponse(http)
	
	CloseHTTPConnection(http)
	DeleteHTTPConnection(http)
	
	token = CountStringTokens(response$,":")
	Response$ = GetStringToken( response$, ":", token )
	Response$ = LEFT(Response$, LEN(Response$)-4)
	Response$ = RIGHT(Response$, LEN(Response$)-1)

EndFunction Response$

the full response appears to be JSON where the first variable "Status" will be 0 on success or 3 on error.

i could parse that but i imagine someone could take the above & properly handle the JSON response?

see the link at the bottom: https://dns.google/query?name=google.com

note: while playing with this i noticed google's IP changes much more frequent than "every 5 minutes" at times.

add: apparently some return multiple IP addresses with a comment that my code doesn't account for:
+ Code Snippet
{
  "Status": 0,
  "TC": false,
  "RD": true,
  "RA": true,
  "AD": false,
  "CD": false,
  "Question": [
    {
      "name": "appgamekit.com.",
      "type": 1
    }
  ],
  "Answer": [
    {
      "name": "appgamekit.com.",
      "type": 1,
      "TTL": 299,
      "data": "172.67.68.13"
    },
    {
      "name": "appgamekit.com.",
      "type": 1,
      "TTL": 299,
      "data": "104.26.3.123"
    },
    {
      "name": "appgamekit.com.",
      "type": 1,
      "TTL": 299,
      "data": "104.26.2.123"
    }
  ],
  "Comment": "Response from 2606:4700:50::adf5:3a6c."
}

so, more parsing required, or, again, proper JSON handling (if possible?).

but, we're getting close.
Posted: 18th Jul 2021 5:12
Fully parsed:
+ Code Snippet
// Project: DNS Lookup 
// Created: 2021-07-16
// By: Virtual Nomad
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "DNS Lookup" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )

// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 ) 

Type VAR
	Label as String
	Value as String
EndType

GLOBAL IP as String []
GLOBAL Status as Integer

URL$ = "appgamekit.com"
Lookup(URL$)

do

    If GetRawKeyState(27) then End
    If Status = 0
		Print(URL$)   
		For x = 0 to IP.Length
			Print(IP[x])
		Next x
	Else
		Print(URL$ + " UnResolved")
	Endif

    Sync()
loop

Function Lookup(URL$)
	http = CreateHTTPConnection()
	SetHTTPHost( http, "dns.google", 1 )
	SendHTTPRequestASync( http, "/resolve?name="+URL$+"&type=A")

	while GetHTTPResponseReady(http) = 0
		Print( "Connecting..." )
		Sync()
	endwhile
	
	Strip(GetHTTPResponse(http))
	
	CloseHTTPConnection(http)
	DeleteHTTPConnection(http)
	
EndFunction

Function Strip(This$)
	Vars$ as VAR []
	Delims$ = "[]{}" + CHR(34)
	New$ = StripString(This$,Delims$)
	total = CountStringTokens(New$, ",")
	
	If total > 0
		for x = 1 to total
			This$ = GetStringToken(New$,",",x)
				That as VAR
				That.Label = GetStringToken(This$,":",1)
				That.Value = GetStringToken(This$,":",2)
			Vars$.Insert(That)
		next x
	Endif
	
	Vars$.Sort()
	Status = Vars$.Find("Status")

	Status = VAL( Vars$[Status].Value )
	If Status = 0
		for x = 0 to Vars$.Length
			If Vars$[x].Label = "data" then IP.Insert(Vars$[x].Value)
		Next x
	Endif
		
EndFunction


reverse lookup with the same method: https://dns.google/query?name=8.8.8.8

added to code snippets
Posted: 19th Jul 2021 0:31
Awesome stuff!!