Jump to content
Sign in to follow this  
adamchapman

InetRead returns hex?

Recommended Posts

adamchapman

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

Share this post


Link to post
Share on other sites
adamchapman

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

Share this post


Link to post
Share on other sites
Cravin

Just for future reference - InetRead() returns values in binary format.  You can then convert into readable text using BinaryToString()

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • Blueman
      By Blueman
      Hi all,
      I was wondering if you can help me with the function called; InetRead().
      My scripts are using this function a lot for several conditions and everything works fine!
      But sometimes when the server is a little bit buggy of simply not available my script is hanging.
      It takes about 90sec before this function returns a Timeout, when i adjust the parameter it still is hanging about 90sec.
      The following script is a example where the script is hanging for aprox. 90sec;
      ; Set Timeout to 2sec AutoItSetOption ("TCPTimeout", 2000) ; Read Website InetRead("http://www.geenverbinding.nl/",1) ; Show Msgbox before Ending Script. Msgbox(64,"","Finished")  
      The following script is a example where the script show the Msgbox pretty fast;

       
      ; Set Timeout to 2sec AutoItSetOption ("TCPTimeout", 2000) ; Read Website InetRead("http://www.google.nl/",1) ; Show Msgbox before Ending Script. Msgbox(64,"","Finished")  
      My question now is, what am i doing wrong and/or is there a other way to prevent Hanging the script?
      Thanks all
       
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
×