The code I posted looks up the public IP address for the domain, records it and notifies me if it has changed so forwarding can be changed. Code has been in use for a couple of years. Just added a setup file.
Also, this is not the same.
This is for private IP addresses from the help file
Like 192.168.0.1 not the public ip address.
Code:
FUNCTION HowManyIPs() AS LONG DIM p AS BYTE PTR LOCAL index AS LONG LOCAL ip AS LONG LOCAL a AS STRING RESET index& DO HOST ADDR(index&+1) TO ip& IF ISTRUE ip& THEN PRINT "counting" INCR index& p = VARPTR(ip&) a$ = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3]) ? a$ END IF LOOP UNTIL ip& = 0 FUNCTION = index& END FUNCTION
This is also incorrect because it only gives the address to the name server.
The name server may be forwarding using your name.
Code:
FUNCTION PBMAIN AS LONG LOCAL ip AS LONG LOCAL p AS BYTE PTR LOCAL a AS STRING HOST ADDR "mysitehere.com" TO ip& p = VARPTR(ip&) a$ = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3]) ? a$
Code:
'This gives public ip even if name server is using forwarding #INCLUDE "win32api.inc" %WaitTime = 30000 'milliseconds to show current IP GLOBAL gMsg AS STRING FUNCTION PBMAIN AS LONG LOCAL hFile AS LONG LOCAL sFile AS STRING LOCAL sIP AS STRING 'previous public ip LOCAL sPublicIP AS STRING 'current public ip from checkip.dyndns.com sFile = "IP.txt" hFile = FREEFILE REM KILL sFile:ERRCLEAR 'erase setup file for testing IF ISFILE(sFile) THEN OPEN sFile FOR INPUT AS #hFile IF ERR THEN ? "Unable to open " + sFile + ". 1-line which is IP address on file: 255.255.255.255 EXIT FUNCTION ELSE LINE INPUT #hFile, sIP 'IP address on file IF ERR THEN ? "LINE INPUT ERROR" + STR$(ERRCLEAR) CLOSE #hFile END IF END IF sPublicIP = GetPublicIP(80,"checkip.dyndns.com","") 'public IP port IF sIP <> sPublicIP THEN ? CHR$(sIp, " (old)", $CRLF, sPublicIP, " (new)",$CRLF,$CRLF, "CHANGE with REGISTRAR!"), +_ %MB_ICONERROR OR %MB_SYSTEMMODAL, sFile 'Update IP address on file ? "Create " + sFile + " updating with public ip " + sPUblicIP hFile = FREEFILE OPEN sFile FOR OUTPUT AS #hFile IF ERR THEN ? "Unable to open for output error" + STR$(ERRCLEAR) PRINT #hFile, sPublicIP 'change to new public ip address change with registrar! CLOSE #hFile ELSE gMsg = sPublicIP SLEEPER %WaitTime 'execute thread if public ip is current END IF END FUNCTION FUNCTION GetPublicIP(PortNumber AS LONG, Site AS STRING, File AS STRING) AS STRING 'modified WebGet LOCAL buffer AS STRING LOCAL temp AS STRING LOCAL i AS LONG LOCAL h AS LONG LOCAL SearchFor AS STRING h = FREEFILE TCP OPEN PORT PortNumber AT site AS #h TIMEOUT 10000 IF ERR THEN BEEP:EXIT FUNCTION TCP PRINT #h, "GET " & file & " HTTP/1.0" TCP PRINT #h, "Accept: */*" TCP PRINT #h, "Accept-Language: en-us" TCP PRINT #h, "Host: " & site TCP PRINT #h, "Pragma: no-cache" TCP PRINT #h, "Referer: URL=http://www.me.com" TCP PRINT #h, "User-Agent: GetIP modified 6/28/2010" TCP PRINT #h, "" DO TCP RECV #h, 4096, buffer temp = temp & buffer LOOP UNTIL LEN(Buffer) = 0 OR ERRCLEAR TCP CLOSE #h REM ? temp SearchFor = "IP ADDRESS" i = INSTR(UCASE$(temp), SearchFor) IF i THEN REM ? "Found at byte" + STR$(i) Temp = MID$(temp,i + LEN(SearchFor)+2) i = INSTR(temp,"</") 'as in /BODY REM ? Temp REM ? "Last byte" + STR$(i) Temp = LEFT$(temp,i-1) REM ? Temp FUNCTION = Temp END IF TCP CLOSE #h END FUNCTION FUNCTION Sleeper (milliseconds AS DWORD) AS LONG LOCAL hThread AS DWORD IF LEN(COMMAND$) THEN 'override passed value milliseconds = ABS(VAL(COMMAND$)) 'use value in COMMAND$ END IF THREAD CREATE TimedMessageBoxThread(milliseconds) TO hThread SLEEP 50 WaitForSingleObject hThread, milliseconds THREAD CLOSE hThread TO hThread END FUNCTION THREAD FUNCTION TimedMessageBoxThread(BYVAL milliseconds AS DWORD) AS LONG 'IP did not change #IF %DEF(%PB_CC32) ? gMsg,,"IP current" WAITKEY$ #ELSE ? gMsg,,"IP current" #ENDIF END FUNCTION
Leave a comment: