Announcement

Collapse
No announcement yet.

get webpage from web http server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • get webpage from web http server

    there are other webget or getweb programs and i believe there is one or more listed in pb forums

    there is mine.

    the initial purpose of this program is to retrieve the internet ip address of the machine running this program.


    Code:
    'compile with pbcc 4.03 or 4.04
    'webgetpg.bas
    'program to get a webpage using the get method of http
    
    
    #COMPILE EXE
    DEFLNG a-z
    
    FUNCTION PBMAIN()
    
    httplocation$=LCASE$(TRIM$(COMMAND$))
    
    
    
    
    IF LEN(httplocation$)>7 THEN
          IF LEFT$(httplocation$,7)="http://" THEN
           serverlocation$=RIGHT$(httplocation$,LEN(httplocation$)-7)
           ELSE
           httplocation$="http://"+httplocation$
          END IF
          
          temp&=INSTR(serverlocation$,"/")
                
          IF temp&>0 THEN
              IF temp&<>LEN(serverlocation$) THEN httplocation$=httplocation$+"/"
              serverlocation$=LEFT$(serverlocation$,temp&-1)
          END IF
          
        ELSE
          PRINT " example to use webgetpg http://www.webservername.com"
        EXIT FUNCTION
    
    END IF
    
        serverport = 80                     'Port (should be 80)
        fileURL$ = httplocation$            'Filename to grab
        
        TCP OPEN PORT serverport AT serverlocation$ AS #1 TIMEOUT 15000    'Open server
        PRINT
        PRINT   "requesting http page from"
        PRINT FILEURL$
        IF ISFALSE(CONSOUT) THEN STDOUT "requesting http page from"
        IF ISFALSE(CONSOUT) THEN STDOUT fileurl$
    
        TCP PRINT #1, "GET " + FILEURL$+ " HTTP/1.0"
        TCP PRINT #1, "Host: " + serverlocation$
        TCP PRINT #1, ""
    
        buffer$=SPACE$(4096)                            'Download file
        received$=""
        IF ERR THEN
           PRINT "server not found"
           IF ISFALSE(CONSOUT) THEN STDOUT "server not found"
           EXIT FUNCTION
        END IF
        DO
            TCP RECV #1, 4096, buffer$      'Download 4k block
            IF buffer$ = "" THEN EXIT DO    'Done?
            received$ = received$ & buffer$ 'Append to total file buffer
        LOOP
        TCP CLOSE #1                        'Disconnect from server
        PRINT  "server found"
        IF ISFALSE(CONSOUT) THEN STDOUT "server found"
    
    received$=TRIM$(received$)
    STDOUT  $CRLF+received$
     IF ISFALSE(CONSOUT) THEN PRINT:PRINT "see redirected output for http page information"
    
    END FUNCTION
    try this
    webgetpg http://www.ioerror.us/ip/headers
    or
    webgetpg http://www.ioerror.us/ip/headers > inetipad.prn

    your program will have to read the ip address from the inetipad.prn

    download webgetpg.exe for a short time from
    http://pdptemp.dyndns.org/zipcode/
    p purvis
Working...
X