This Power Basic 8.0 snippet fetches your external IP address OR beeps.
' find our ip address by fetching a page from whatismyip.com
hTCP&=FREEFILE
TCP OPEN "www" AT "www.whatismyip.com" AS hTCP&
IF ERR THEN
BEEP
ELSE
TCP PRINT hTCP&,_
"GET / HTTP/1.1" +CHR$(13)+CHR$(10)+_
"Host: www.whatismyip.com" +CHR$(13)+CHR$(10)+_
"Accept: text/html, */*" +CHR$(13)+CHR$(10)+_
"Accept-Encoding: identity"+CHR$(13)+CHR$(10)+_
"User-Agent: Mozilla/3.0" +CHR$(13)+CHR$(10)
TCP RECV hTCP&, 2048, buffer$
TCP CLOSE hTCP&
REGEXPR "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" IN buffer$ TO iPOS&, iLEN&
IF iPOS&>0 THEN ' save the present ip..
myip$ = MID$(buffer$,iPOS&, iLEN&)
CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, myip$
outfile&=FREEFILE
OPEN "oldip.txt" FOR OUTPUT AS #outfile&
WRITE #outfile&, myip$
CLOSE #outfile&
END IF
END IF
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment