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

    • badcoder123
      By badcoder123
      Hey, all.  
      I've been looking for a way to change cursor colour but not the cursor itself. I've been looking for a couple hours now and can't find anything.  I also don't even know where to start, if anyone has any tips or examples please comment them.
      Thanks
    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • 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"
×