;--------------------------------------- ; LocalProxy-HostViewer.au3 ; Released: February 03, 2017 ; Version: 1.00 ; Author: ripdad ; ; Modified: February 17, 2017 - tweaked ;--------------------------------------- ; #NoTrayIcon Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) ; Local Const $sTitle = 'LocalProxy-HostViewer' Local Const $sPathIcon = @WindowsDir & '\system32\shell32.dll' TraySetIcon($sPathIcon, 19) TraySetToolTip($sTitle) ; If Not TCPStartup() Then Exit MsgBox(8208, $sTitle, 'Error: TCPStartup' & @TAB, 5) EndIf ; Local $nSocketHTTP = TCPListen('127.0.0.1', 8080) If @error Then Local $msg = 'Error: HTTP Proxy could not bind socket on IP: 127.0.0.1, Port: 8080' Exit MsgBox(8208, $sTitle, $msg & @TAB, 5) EndIf ; Local $sHeader, $sHost, $sMethod, $nSocket, $sRecv, $str, $Active = 0 Local $s404 = 'HTTP/1.1 404 Not Found' & @CRLF $s404 &= 'Server: LocalProxy' & @CRLF $s404 &= 'Content-Length: 0' & @CRLF $s404 &= 'Connection: close' & @CRLF & @CRLF ; DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 1) Local $ID_GUI = GUICreate($sTitle, 350, 265, Default, Default, Default, 8) GUISetFont(8.5, Default, Default, 'microsoft sans serif') GUISetIcon($sPathIcon, 19, $ID_GUI) Local $ID_EDT = GUICtrlCreateEdit('', 5, 5, 340, 220) Local $ID_BTN = GUICtrlCreateButton('Clear', 145, 235, 60, 20, 0x1002) GUICtrlSetTip($ID_BTN, 'Clear the Window') GUICtrlSetOnEvent($ID_BTN, 'EditClear') GUICtrlSetLimit($ID_EDT, 10000) GUISetOnEvent(-3, 'Minimize') OnAutoItExitRegister('ExitApp') GUISetState(@SW_SHOW, $ID_GUI) GUICtrlSetState($ID_EDT, 256) Opt('GUIOnEventMode', 1) ; While 1 Do Sleep(100) $nSocket = TCPAccept($nSocketHTTP) If $nSocket > 0 Then $Active = 1 EndIf Until $Active ; For $i = 1 To 25 $sRecv = TCPRecv($nSocket, 1024, 1) If StringLen($sRecv) > 1 Then $sRecv = BinaryToString($sRecv) $sMethod = StringLeft($sRecv, StringInStr($sRecv, ' ') - 1) If StringRegExp($sMethod, '(?i)(GET|CONNECT|POST)') Then $sHost = StringRegExpReplace($sRecv, '(?is).*Host:\s(.*?)\r\n.*', '\1') $str = GUICtrlRead($ID_EDT) GUICtrlSetData($ID_EDT, '') GUICtrlSetData($ID_EDT, $sHost & @CRLF & $str) TCPSend($nSocket, $s404) ExitLoop EndIf EndIf Sleep(10) Next TCPCloseSocket($nSocket) $Active = 0 WEnd ; Func Minimize() GUISetState(@SW_MINIMIZE, $ID_GUI) EndFunc ; Func EditClear() GUICtrlSetState($ID_EDT, 256) GUICtrlSetData($ID_EDT, '') EndFunc ; Func ExitApp() GUIDelete($ID_GUI) TCPShutdown() Exit EndFunc ;