Jump to content

InetRead returns hex?


Recommended Posts

I'm using InetRead to access a machine's ID on the amazon ec2 service. 

 

to access the string containing the machine's ID I'm using the line:

$instanceID = InetRead("http://169.254.169.254/latest/meta-data/instance-id",4)

ConsoleWrite($instanceID)
ConsoleWrite(@CRLF)

$instanceID = StringLeft($instanceID,10) ; use the first ten characters

ConsoleWrite($instanceID)
ConsoleWrite(@CRLF)

I think the "4" option in the InetRead function call should force ASCII format, but it must be struggling. 

 

The first ConsoleWrite returns: i-aa0fa69e (which is the properly formatted machine ID)

and the second ConsoleWrite returns: 0x692D6161

 

which appears to be the hex equivalent of the original string.

 

Does any body know how I can force the $instanceID variable to be an ASCII string?

 

This one is really confusing me

 

 

 

Edited by adamchapman
Link to comment
Share on other sites

Found a solution, although fairly long-winded:

ocal $hDownload = InetGet("http://169.254.169.254/latest/meta-data/instance-id","localID.txt",4,1)
ConsoleWrite("reading ID..." & @CRLF)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2) ; Check if the download is complete.

InetClose($hDownload) ; Close the handle to release resources.


; Now read that file in ASCII:
$Localidf=FileOpen("localID.txt", 0); read mode, no write permission LOCAL ID FILE
$instanceID = FileReadLine($LocalIDf, 1)
ConsoleWrite($instanceID)
ConsoleWrite(@CRLF)
FileClose($LocalIDf)

Writing the page text to a file with InetGet while forcing ASCII in the INetGet options, than reading the file back works fine. Strange how InetRead didn't act the same way though

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...