Jump to content

GetServerHTTPHeader


Yuraj
 Share

Recommended Posts

Hi all,

I have written this script - it's for getting HTTP header entry of host, it doesn't read entire HTTP response, only header and if it found that entry then stops receiving datas.

Func GetServerHTTPHeader($host,$httpEntry,$port=80)
    ; INITIALIZE TCP
    TCPStartup()

    ; CONNECT
    $ip = TCPNameToIP($host)
    $socket = TCPConnect($ip,$port)

    ; SEND HTTP GET
    $sent = TCPSend($socket,"GET / HTTP/1.1"&@CRLF&"Host: "&$host&@CRLF&"User-agent: none"&@CRLF&"Connection: close"&@CRLF&@CRLF)

    ; RECIEVE DATA
    Local $recData = ""
    Local $data = ""
    Local $lastData = ""
    Local $date = ""

    While 1
        $recData = TCPRecv($socket,1) ; Recieve byte
        
        ; Check if is end of HTTP header or @error
        If @error Or ($lastData & $data) == @CRLF Then ExitLoop

        ; Join last recieved char
        If $recData <> "" Then
            $data &= $recData
        EndIf
        
        ; If is current char end of line, get current line
        If $recData == @LF Then
            $ln = StringStripWS(StringTrimRight($data,2),2)
            ; Check for date HTTP header section
            If StringLeft(StringLower($ln),StringLen($httpEntry)) == $httpEntry Then
                $date = $ln
                ExitLoop
            Else ; if not found - continue
                $lastData = $data ; Set last data
                $data = "" ; Clear current line
            EndIf
        EndIf
        
    WEnd

    ; CLOSE SOCKET
    TCPCloseSocket($socket)
    TCPShutdown()
    
    If $date == "" Then  SetError(1) ; Set error cuz not found date
    Return $date
EndFunc

//Sorry for my bad english

ShellExecute("http://www.yuraj.ucoz.com")ProcessClose(@AutoItPID)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...