Code: Alles auswählen
Global Content$
Global Host$
Global Referer$
Global Bla1$
Global Bla2$
Global Bla3$
Global Bla4$
Global Bla5$
Global Bla6$
Global Bla7$
Global Bla8$
Global Bla9$
Global Bla10$
InitNetwork()
Procedure OpenNetworkConnectionEx(ServerName.s,Port.l,TimeOut.l,Type.l = #PB_Network_TCP)
Timeout$ = GetGadgetText(7)
TimeOut.l = Val(Timeout$)
Protected WSAD.WSADATA, TV.TIMEVAL, Addr.SOCKADDR_IN, *HostInfo.HOSTENT, Write_FD.FD_SET
Protected S.l, Switch.l, Retval.l, ServerIP.s
TV\tv_sec = TimeOut
Switch = #True
If Type = #PB_Network_UDP
ProcedureReturn OpenNetworkConnection(ServerName,Port,#PB_Network_UDP)
EndIf
If WSAStartup_($202,@WSAD)
ProcedureReturn #False
EndIf
*HostInfo = gethostbyname_(@ServerName)
If *HostInfo
ServerIP = StrU(PeekB(PeekL(*HostInfo\h_addr_list)),0) + "."
ServerIP + StrU(PeekB(PeekL(*HostInfo\h_addr_list) + 1),0) + "."
ServerIP + StrU(PeekB(PeekL(*HostInfo\h_addr_list) + 2),0) + "."
ServerIP + StrU(PeekB(PeekL(*HostInfo\h_addr_list) + 3),0)
EndIf
Debug ServerIP
S = SOCKET_(#AF_INET,#SOCK_STREAM,#IPPROTO_TCP)
If S = #SOCKET_ERROR
WSACleanup_()
ProcedureReturn #False
EndIf
ioctlsocket_(S,#FIONBIO,@Switch)
With Addr
\sin_addr = inet_addr_(ServerIP)
\sin_port = htons_(Port)
\sin_family = #AF_INET
EndWith
Debug Addr.SOCKADDR_IN\sin_addr
Debug Addr.SOCKADDR_IN\sin_port
Debug Addr.SOCKADDR_IN
connect_(S,@Addr,SizeOf(Addr))
With Write_FD
\fd_count = 1
\fd_array[0] = S
EndWith
Repeat
Retval = select_(0,0,@Write_FD,0,@TV)
Until Retval >= 0
closesocket_(S)
WSACleanup_()
If Retval
ProcedureReturn OpenNetworkConnection(ServerName,Port)
EndIf
EndProcedure
If OpenWindow(0,0,0,600,500,"Timeout",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(1,200,350,100,20,"Start")
EditorGadget(2,10,10,500,280)
StringGadget(3,10,400,480,20,"http://wikipedia.de/");ZIEL
StringGadget(4,10,430,480,20,"http://www.google.com/");REFERER
CheckBoxGadget(5,200,320,100,20,"Use Proxy")
StringGadget(6,10,300,480,20,"");PROXY
StringGadget(7,10,320,20,20,"10",#PB_String_Numeric);Server/Proxy CONNECT Timeout
Repeat
WaitWindowEvent = WaitWindowEvent()
EventGadget = EventGadget()
If WaitWindowEvent = #PB_Event_Gadget
If EventGadget = 1
URL$=GetGadgetText(3)
Referer$=GetGadgetText(4)
url_total_len = Len(URL$)
HOST_PART$ = Right(URL$, url_total_len -7)
host_slash_pos = FindString(HOST_PART$, "/", 1)
Host$ = Left(HOST_PART$, host_slash_pos-1)
jaja = Len(HOST_PART$)
Content$ = Right(HOST_PART$, jaja - host_slash_pos +1)
Debug Content$+" Content"
Debug Host$+" Host"
Debug URL$+" URL"
;-HTTP HEADER
If Proxy_Option = 1
Bla1$="GET "+URL$+" HTTP/1.0"+#CRLF$;mit Proxy
Else
Bla1$="GET "+Content$+" HTTP/1.1"+#CRLF$
EndIf
Bla2$="Host: "+Host$+#CRLF$
Bla3$="Connection: close"+#CRLF$
Bla4$="Accept-Encoding: gzip"+#CRLF$
Bla5$="Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1"+#CRLF$
Bla6$="Accept-Language: en-us,en;q=0.7,de-de;q=0.3"+#CRLF$
Bla7$="Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7"+#CRLF$
Bla8$="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; rv:1.7.13) Gecko/20070216"+#CRLF$
Bla9$="Referer: "+Referer$+#CRLF$
Bla10$=#CRLF$
;-
#TimeOut = 5 ; in Sekunden
Proxy_Option = GetGadgetState(5)
If Proxy_Option = 1
Proxy$ = GetGadgetText(6)
KNOLLE = FindString(Proxy$,":",1)
P_IP$ = Left(Proxy$,KNOLLE -1)
Debug P_IP$
Proxy_Len = Len(Proxy$)
Final_Len = Proxy_Len - KNOLLE
P_PORT$ = Right(Proxy$,Final_Len)
Debug P_PORT$
P_Port.l = Val(P_PORT$)
Define id.l = OpenNetworkConnectionEx(P_IP$,P_Port.l,#TimeOut);mit Proxy
Else
Define id.l = OpenNetworkConnectionEx(Host$,80,#TimeOut);ohne Proxy
EndIf
;- USER:Password
; InputCombo2$ = "hans:wurst"
; ComboLength2 = Len(InputCombo2$)
; OutputAuth2$ = Space(256)
; Base64Encoder(@InputCombo2$, ComboLength2, @OutputAuth2$, 255)
; U_P$ = "Authorization: Basic "+OutputAuth2$+#CRLF$
; Debug U_P$
;-
If id
Debug "-------SEND DATA--------"
Debug "---HTTP OUTPUT HEADER---"
Debug Bla1$
Debug Bla2$
Debug Bla3$
Debug Bla4$
Debug Bla5$
Debug Bla6$
Debug Bla7$
Debug Bla8$
Debug Bla9$
;Debug U_P$
Debug "------------------------------------"
Debug ""
SendNetworkString(id.l, Bla1$+Bla2$+Bla3$+Bla4$+Bla5$+Bla6$+Bla7$+Bla8$+Bla9$+U_P$+Bla10$)
*mem1=AllocateMemory(4000)
SetGadgetText(2,"")
DisableGadget(2,1)
Delay(500)
;-DELAY TIMEOUT AFTER CONNECTION
killer = 0
kill_val = 3999999 ;- ~5 Sek
dat_end_size = 0
;-
Repeat
killer = killer + 1
checker= NetworkClientEvent(id)
If checker = #PB_NetworkEvent_Data
If killer <= kill_val And checker >= 2
Receive_Ergebnis = ReceiveNetworkData(id.l,*mem1,4000)
If Receive_Ergebnis >= 1
Debug "-----INCOMING DATA------"
dat1$=PeekS(*mem1)
dat1$=LCase(dat1$)
Debug dat1$
dat_size=StringByteLength(dat1$)
dat_end_size = dat_size + dat_size
OK200_Status_Code = FindString(dat1$,"200 ok",1)
PW_401 = FindString(dat1$,"401 unauthorised",1)
If OK200_Status_Code <> 0
AddGadgetItem(2,-1,dat1$,Spalte)
Debug ""
Debug " OK "
FreeMemory(*mem1)
*mem1=AllocateMemory(4000)
Break
ElseIf PW_401 <> 0
AddGadgetItem(2,-1,dat1$,Spalte)
Debug " "
Debug "User and Pass Required"
FreeMemory(*mem1)
*mem1=AllocateMemory(4000)
Break
EndIf
FreeMemory(*mem1)
*mem1=AllocateMemory(4000)
Else
If dat_end_size = 0
Debug "RECEIVED 0 BYTES"
Break
Else
Debug "RECEIVED "+dat_end_size$+" BYTES"
Break
EndIf
EndIf
ElseIf checker = 0 And killer >= kill_val
Break
EndIf
ElseIf checker = 0 And killer >= kill_val
If dat_end_size = 0
Debug "RECEIVE STATUS = TIMEOUT"
Debug "RECEIVED 0 BYTES"
DisableGadget(2,0)
Else
Debug "RECEIVE STATUS = TIMEOUT "
dat_end_size$ = Str(dat_end_size)
Debug "RECEIVED "+dat_end_size$+" BYTES"
DisableGadget(2,0)
EndIf
Break
EndIf
Until id = 0 Or killer >= kill_val
Debug ""
Debug "---------------------------------------"
Debug "OPEN CONNECTION = war erfolgreich"
CloseNetworkConnection(id)
DisableGadget(2,0)
Else
Debug ""
Debug "---------------------------------------"
Debug "OPEN CONNECTION = Timeout oder Fehler"
SetGadgetText(2,"OPEN CONNETION = TIMEOUT")
EndIf
EndIf
EndIf
Until WaitWindowEvent = #PB_Event_CloseWindow
EndIf
End