/* Arexx myip.org client ©2000 Michael Trebilcock */
Options Results
Parse Arg Args

/* Configuration */
dynid="" /* Your ID at myip.org, in uppercase */
dynpwd="" /* Your password at myip.org */
hostname="" /* <host>.myip.org you wish to update */
/* End Configuration */

Quote=d2c(34)
CR="0D"x

IF Right(Upper(hostname),9)~=".myip.org" THEN hostname=hostname".myip.org"
IP=Args

IF IP="" THEN DO
 IF ~Open(File,"ENV:HOST","RW") THEN DO
  Call cEcho("Unable to grab your hostname, enter your ip in manually..")
  Exit
 End
 IP=GetNumIP(ReadLn(File))
 IF IP="IP"|IP="" THEN DO
  Call cEcho("Unable to grab your IP, enter your ip in manually..")
  Call Close(File)
  Exit
 End
 Call Close(File)
End

Length=Length("id="dynid"&pwd="dynpwd"&hostname="hostname"&ip="IP"&recordtype=A")

Call cEcho("Connecting to www.myip.org, please wait..")
IF ~Open(TCP,"TCP:www.myip.org/80","RW") THEN DO
 Call cEcho("Unable to connect, try again later..")
 Exit
End
Call cEcho("Connected, updating "hostname"..")

Call WriteLn(TCP,"POST /cgi-bin/Update.py HTTP/1.0"CR)
Call WriteLn(TCP,"User-Agent: Amiga-AWeb/3.3"CR)
Call WriteLn(TCP,"Accept: */*;q=1"CR)
Call WriteLn(TCP,"Host: www.myip.org"CR)
Call WriteLn(TCP,"Referer: http://www.myip.org/cgi-bin/Login.py"CR)
Call WriteLn(TCP,"Content-Length: "Length""CR)
Call WriteLn(TCP,"Content-Type: application/x-www-form-urlencoded"CR)
Call WriteLn(TCP,"Cookie: dynid="dynid"; $Path="Quote"/"Quote"; dynpwd="dynpwd"; $Path="Quote"/"Quote""CR)
Call WriteLn(TCP,CR)

Call WriteLn(TCP,"id="dynid"&pwd="dynpwd"&hostname="hostname"&ip="IP"&recordtype=A")

IF Word(ReadLn(TCP),2)~="200" THEN DO
 Call cEcho("An error occured, unable to update hostname..")
 Call Close(TCP)
 Exit
End

DO UNTIL EOF(TCP)
 Call ReadLn(TCP)
End

Call cEcho(hostname "is now updated..")
Call Close(TCP)
Exit

cEcho:
"ECHO P="d2c(27)"b«MyIP» TEXT="Arg(1)
Return 0
