Jump to content
slaughter

Au3 Proxy For VNC

Recommended Posts

slaughter

updated: Was en error in code. Now is working but still have same problem.

Hello geek's

I have worked over 3 day's on this script. As far as i am now:

I will explane what purpose of this proxy server. I have in my LAN 20 virtual servers (winXP OS) with some kind of software on them. I cant use MS terminal server because of software restrictions so i made 20 separeted virtual PC. They have thier own IP and UltraVNC server instaled.

I have 60~ users who time to time whant to use them. A the same time there thre will not be more then 20 users using VNC servers.

At the same moment I cant connect more then 1 user at the same VNC server.

So baisicly this script listen on single port acepting inbuot internet or LAN conections and proxyng them to unused vnc server on LAN.

This culd be used for any kind of server. Just nead more work on it :P

Isues what i have is:

* How to detect when conection from user or Vnc server is closed. when detection is made thet user closed vnc connection to close socket and mark VNC server IP as unused by asinging to it value -1

Bugs:

Until you do not disconet vnc viever it works fine. as son as you colose conection it starts mesing. some times works some times not. Try yourself :/

Code

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <array.au3>
#include <inet.au3>
#include <String.au3>
#Include <File.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 0)

;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================





    Global $szIPADDRESS = @IPAddress1
    Global $nPORT = 33891
    Global $MainSocket, $GOOEY, $szIP_Accepted1, $szIP_Accepted2,  $Free_socket, $msg, $recv1, $recv2, $Track, $hListView
    Global $edit
    Global $server_to_adr
    Global $server_to_port = "5900"
    
    Global Const $MaxConnection = 100; Maximum user connections
    Global $ConnectedSocket1[ ($MaxConnection + 1) ]
    Global $ConnectedSocket2[ ($MaxConnection + 1) ]
    
    Dim $vnc_servers_tmp
    _FileReadToArray("vncList.txt",$vnc_servers_tmp)
    Global $vnc_servers
    Dim $vnc_servers[UBound($vnc_servers_tmp)][2]
    
For $Track=1 to $vnc_servers_tmp[0] Step 1
$vnc_servers[$Track][0] = $vnc_servers_tmp[$Track]
$vnc_servers[$Track][1] = -1
Next

    

;~ _ArrayDisplay($vnc_servers, "f")



Example()

Func Example()
; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)

    
; Null all socets
;---------------------------------------------
    For $Track = 0 To $MaxConnection Step 1
        $ConnectedSocket1[$Track] = -1
        $ConnectedSocket2[$Track] = -1
    Next
;--------------------------------------------

    
; Start The TCP Services
;==============================================
    TCPStartup()

; Create a Listening "SOCKET".
;   Using your IP Address and Port 33891.
;==============================================

  $MainSocket = TCPListen($szIPADDRESS, $nPORT)

; If the Socket creation fails, exit.
    If $MainSocket = -1 Then Exit


; Create a GUI for messages
;==============================================
    $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 800, 200)
    $edit = GUICtrlCreateEdit("", 10, 10, 480, 180)
    $hListView = GUICtrlCreateListView("", 490, 10, 300, 180)
        _GUICtrlListView_AddColumn($hListView, "VNC Server IP", 190)
        _GUICtrlListView_AddColumn($hListView, "socket", 70)
            _GUICtrlListView_AddArray($hListView, $vnc_servers)
    GUISetState()


; Initialize a variable to represent a connection
;==============================================
;~   $ConnectedSocket1 = -1
;~   $ConnectedSocket2 = -1



; GUI Message Loop
;==============================================
    While 1
        
    ;Wait for and Accept a connection
;==============================================
    $Free_socket = SocketSearch()
    
$ConnectedSocket1[$Free_socket] = TCPAccept($MainSocket)

If $ConnectedSocket1[$Free_socket] <> -1 Then
 ;Check socket  usage
        Scan_sockets()
        $server_to_adr = find_vnc($Free_socket)
 ; Connect to other host whre to send recieved data
        $ConnectedSocket2[$Free_socket] = TCPConnect($server_to_adr, $server_to_port)
 ; Get IP of client connecting
        $szIP_Accepted1 = SocketToIP($ConnectedSocket1[$Free_socket])
        $szIP_Accepted2 = SocketToIP($ConnectedSocket2[$Free_socket])
Add_msg("User conected from IP: "&$szIP_Accepted1& " to IP: "&$szIP_Accepted2)
Add_msg("Using socket: " &$Free_socket)

    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView)); items added with UDF function can be deleted using UDF function
    _GUICtrlListView_AddArray($hListView, $vnc_servers)

;~ _ArrayDisplay($vnc_servers, "servers")
EndIf
                                                                                                                    
        $msg = GUIGetMsg()

    ; GUI Closed
    ;--------------------
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop


For $Track = 0 To $MaxConnection Step 1
    If $ConnectedSocket1[$Track] <> - 1 Then

 ; Try to receive (up to) 2048 bytes
    ;----------------------------------------------------------------
        $recv1 = TCPRecv($ConnectedSocket1[$Track], 2048)
    ; If the receive failed with @error then the socket has disconnected
    ;----------------------------------------------------------------
;~       If @error Then ExitLoop
    ; Try to receive (up to) 2048 bytes
    ;----------------------------------------------------------------
        $recv2 = TCPRecv($ConnectedSocket2[$Track], 2048)
    ; If the receive failed with @error then the socket has disconnected
    ;----------------------------------------------------------------
;~       If @error Then ExitLoop

    ; Update the edit control with what we have received
    ;----------------------------------------------------------------
        Local $ret
        If $recv1 <> "" Then 
        $ret = TCPSend($ConnectedSocket2[$Track], $recv1)
;~       If @error Or $ret < 0 Then openSocket($Track)
        EndIf
        
        If $recv2 <> "" Then 
        $ret = TCPSend($ConnectedSocket1[$Track], $recv2)
;~       If @error Or $ret < 0 Then openSocket($Track)
        EndIf
    
;~       If $ConnectedSocket1[$Track] = -1 Then 
;~       TCPCloseSocket($ConnectedSocket1[$Track])
;~       Add_msg("User disconected " & SocketToIP($ConnectedSocket2[$Track]))
;~       EndIf
    EndIf
    
Next
    
WEnd
            
;~ 192.168.1.135





;~   Add_msg("Shudown..")
;~   TCPShutdown()
EndFunc;==>Example


Func find_vnc($SHOCKET)
    Local $Trackm
For $Trackm=1 to $vnc_servers_tmp[0] Step 1
    if $vnc_servers[$Trackm][1] = -1 Then 
    $vnc_servers[$Trackm][1] = $SHOCKET
    Return $vnc_servers[$Trackm][0]
    EndIf
Next

EndFunc




Func openSocket($SHOCKETm)
    Local $iIndex 
        Add_msg("User disconected Socket: " &$SHOCKETm& " IP: "& SocketToIP($ConnectedSocket1[$SHOCKETm]))
    TCPCloseSocket($ConnectedSocket2[$SHOCKETm])
    TCPCloseSocket($ConnectedSocket1[$SHOCKETm])
        $ConnectedSocket1[$SHOCKETm] = -1
        $ConnectedSocket2[$SHOCKETm] = -1
        
    $iIndex = _ArraySearch($vnc_servers, $SHOCKETm, 0, 0, 0, 1, 1)
    If @error Then
        Add_msg("Cand find server to free up for disconected socket" & $SHOCKETm)
    Else
        $vnc_servers[$iIndex][1] = -1
        Add_msg("Server sucesfuly found VNC server to free up for disconected socket" & $SHOCKETm)
    EndIf
EndFunc

Func Scan_sockets()
    Add_msg("Socket scandig start")
    Local $ret, $Trackp
    For $Trackp = 0 To $MaxConnection Step 1
    if $ConnectedSocket1[$Trackp] <> -1 Then
        $ret = TCPSend($ConnectedSocket1[$Trackp], "")
        If @error Or $ret < 0 Then 
            openSocket($Trackp) 
        EndIf
        $ret = TCPSend($ConnectedSocket2[$Trackp], "")
        If @error Or $ret < 0 Then 
            openSocket($Trackp) 
        EndIf
    EndIf
    Next
    Add_msg("Socket scandig end")
EndFunc


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    Local $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc;==>SocketToIP

;Function to add text to gui text area
;----------------------------------------------------------------------
Func Add_msg($msg)
    Global $edit
    GUICtrlSetData($edit, " >  " & $msg & @CRLF & GUICtrlRead($edit))
EndFunc;==>Add_msg
            
            
Func SocketSearch()
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket1[$Track] = -1 Then Return $Track
    Next
EndFunc;==>SocketSearch

vncList.txt

192.168.1.124
192.168.1.127
192.168.1.140
192.168.1.197
192.168.1.196
192.168.1.132
192.168.1.133
192.168.1.137
192.168.1.136
192.168.1.109
192.168.1.118
192.168.1.174
192.168.1.120
192.168.1.128
192.168.1.109
192.168.1.117
192.168.1.110
192.168.1.130
192.168.1.103
192.168.1.135
192.168.1.136
Edited by slaughter

Share this post


Link to post
Share on other sites
BrettF
slaughter

This is general help, so whats the problem?

How to detect that user o server has finished his connection.

I use this function to scan sockets but this function sometimes works and most of time it does not

Func Scan_sockets()
    Add_msg("Socket scandig start")
    Local $ret, $Trackp
    For $Trackp = 0 To $MaxConnection Step 1
;tryes to detect on array witch sockets are in use
    if $ConnectedSocket1[$Trackp] <> -1 Then
;if in array socket is market not -1 that means socket is used or was used 
    $ret = TCPSend($ConnectedSocket1[$Trackp], "")
;tryes to send using socket null data
        If @error Or $ret < 0 Then openSocket($Trackp)
;if gets error then in array shuld mar that socket is not used and VNC server is free   
    EndIf
    $ret = TCPSend($ConnectedSocket2[$Trackp], "")
        If @error Or $ret < 0 Then openSocket($Trackp)  
    EndIf
    Next
    Add_msg("Socket scandig end")
EndFunc
Edited by slaughter

Share this post


Link to post
Share on other sites
slaughter

Sory was error in main code now fixed. Bu i stll nead help with this function. Maybe anyone tryed it ?

Here is the JPG for what im making here :P

post-3048-1236256253_thumb.jpg

Share this post


Link to post
Share on other sites
slaughter

Sory was error in main code now fixed. Bu i stll nead help with this function. Maybe anyone tryed it ?

Here is the JPG for what im making here :P

post-3048-1236256253_thumb.jpg

Bumpt

Share this post


Link to post
Share on other sites
slaughter

Works for windows RDP (Remote desktop connection) protocol and for VNC, just have to change ports

Server works ruond robin principal one connecton per server.

BUGS:

*Laggg when more than 7~10 users connected..... (nead help, cant find why)

*some times does not detects disconet.....

list of ip adreses to acept connection from

alowed_ip.txt
192.168.1.*
192.168.*.*
127.0.0.1

Txt file with list of computer with vnc or rdp server

vncList.txt
192.168.1.*
192.168.*.*
127.0.0.1

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <array.au3>
#include <inet.au3>
#include <String.au3>
#Include <File.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Timers.au3>
Opt('MustDeclareVars', 0)

;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================

write_log("starting up server")



    Global $szIPADDRESS = InputBox("PoP IP", "IP", @IPAddress2)
    Global $nPORT = InputBox("PoP IP", "port", "5901")
    Global $MainSocket, $GOOEY, $szIP_Accepted1, $szIP_Accepted2,  $Free_socket, $msg, $recv1, $recv2, $Track, $hListView, $vnc_alowed
    Global $edit
    Global $server_to_adr
    Global $server_to_port = InputBox("PoP IP", "posrt", "5900")
    Global Const $MaxConnection =100
    Global $ConnectedSocket1[ ($MaxConnection + 1) ]
    Global $ConnectedSocket2[ ($MaxConnection + 1) ]

write_log("Global configuration set")
write_log("Server ip: "& $szIPADDRESS)
write_log("Server port: "& $nPORT)
write_log("Redirect port: "& $server_to_port)

    Dim $vnc_servers_tmp
    Dim $vnc_alowed
write_log("Reading server list")
    _FileReadToArray("vncList.txt",$vnc_servers_tmp)
write_log("Reading alowed ip addresses")
    _FileReadToArray("alowed_ip.txt",$vnc_alowed)

write_log("Starting Server configuration calculations")
;Atvaidavimo array
write_log("Generating display array")
    Global $gui_display
Dim $gui_display[UBound($vnc_servers_tmp)+2][7]
;Serverio vidiniams skaiciavimams
write_log("Generating arays for local calculations")
    Global $vnc_servers
    Dim $vnc_servers[UBound($vnc_servers_tmp)+2][7]
write_log("Reseting arrays to emty")
For $Track=1 to $vnc_servers_tmp[0] Step 1
$vnc_servers[$Track][0] = $vnc_servers_tmp[$Track]
$vnc_servers[$Track][1] = -1
$gui_display[$Track][0] = $vnc_servers_tmp[$Track]
Next



;~ _ArrayDisplay($vnc_servers, "f")



Example()

Func Example()
   ; Set Some reusable info
   ; Set your Public IP address (@IPAddress1) here.
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)


write_log("Null all socets")
;---------------------------------------------
    For $Track = 0 To $MaxConnection Step 1
        $ConnectedSocket1[$Track] = -1
        $ConnectedSocket2[$Track] = -1
    Next
;--------------------------------------------


   write_log(" Start The TCP Services")
   ;==============================================
    TCPStartup()

   write_log("Create a Listening SOCKET")
   ;   Using your IP Address and Port 33891.
   ;==============================================

  $MainSocket = TCPListen($szIPADDRESS, $nPORT)

   ; If the Socket creation fails, exit.
    If $MainSocket = -1 Then
        write_log("Error socket cration")
        Exit
    EndIf


   ; Create a GUI for messages
   write_log("Creating Gui")
   ;==============================================
    $GOOEY = GUICreate("Proxy Of Proxy :D (IP: " & $szIPADDRESS & ")", 800, 200)
;~     $edit = GUICtrlCreateEdit("", 10, 10, 480, 180)
    $hListView = GUICtrlCreateListView("", 10, 10, 780, 180)
        _GUICtrlListView_AddColumn($hListView, "VNC Server IP", 90)
        _GUICtrlListView_AddColumn($hListView, "S", 30)
        _GUICtrlListView_AddColumn($hListView, "Client IP", 90)
        _GUICtrlListView_AddColumn($hListView, "Connection Time", 150)
        _GUICtrlListView_AddColumn($hListView, " ", 50)
        _GUICtrlListView_AddColumn($hListView, " ", 50)
        _GUICtrlListView_AddArray($hListView, $gui_display)
    GUISetState()


   ; Initialize a variable to represent a connection
   ;==============================================
;~     $ConnectedSocket1 = -1
;~     $ConnectedSocket2 = -1


AdlibEnable("Gui_update", 5000)

   ; GUI Message Loop
   ;==============================================
    While 1

       ;Wait for and Accept a connection
   ;==============================================
    $Free_socket = SocketSearch()

$ConnectedSocket1[$Free_socket] = TCPAccept($MainSocket)

If $ConnectedSocket1[$Free_socket] <> -1 Then


;Check socket  usage
;~         Scan_sockets()
        $server_to_adr = find_vnc($Free_socket)

            _FileReadToArray("alowed_ip.txt",$vnc_alowed)
                match_ip_array($vnc_alowed, SocketToIP($ConnectedSocket1[$Free_socket]))
                ;ConsoleWrite(SocketToIP($ConnectedSocket1[$Free_socket]))
            if @error Then
                openSocket($Free_socket)
                write_log("Blocked: IP "&SocketToIP($ConnectedSocket1[$Free_socket])&" is not in list to accept")
            Else
                write_log("Acepted: IP "&SocketToIP($ConnectedSocket1[$Free_socket])&" is in list to accept")



    ; Connect to other host whre to send recieved data
            $ConnectedSocket2[$Free_socket] = TCPConnect($server_to_adr, $server_to_port)
    ; Get IP of client connecting
                $szIP_Accepted1 = SocketToIP($ConnectedSocket1[$Free_socket])
                $szIP_Accepted2 = SocketToIP($ConnectedSocket2[$Free_socket])
                $vnc_servers[$Free_socket+1][2]= $szIP_Accepted1
                $gui_display[$Free_socket+1][2]= $szIP_Accepted1
                $gui_display[$Free_socket+1][3]= @YEAR &"-"& @MON &"-"& @MDAY &"-"& @HOUR &":"& @MIN &":"& @SEC
                ConsoleWrite($gui_display[$Free_socket+1][3])
            EndIf
;~ _ArrayDisplay($vnc_servers, "servers")
EndIf

        $msg = GUIGetMsg()

       ; GUI Closed
       ;--------------------
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop


For $Track = 0 To $MaxConnection Step 1
    If $ConnectedSocket1[$Track] <> - 1 Then
        $vnc_id = Get_srv_id($Track)
    ; Try to receive (up to) 2048 bytes
       ;----------------------------------------------------------------
        $recv1 = TCPRecv($ConnectedSocket1[$Track], 10240*10)
        If @error Then
            openSocket($Track)
        EndIf

       ; If the receive failed with @error then the socket has disconnected
       ;----------------------------------------------------------------
;~         If @error Then ExitLoop
       ; Try to receive (up to) 2048 bytes
       ;----------------------------------------------------------------
        $recv2 = TCPRecv($ConnectedSocket2[$Track], 10240*10)
        If @error Then
            openSocket($Track)
        EndIf
        ; If the receive failed with @error then the socket has disconnected
       ;----------------------------------------------------------------
;~         If @error Then ExitLoop

       ; Update the edit control with what we have received
       ;----------------------------------------------------------------
        Local $ret

        If $recv1 <> "" Then
        $ret = TCPSend($ConnectedSocket2[$Track], $recv1)
        EndIf

        If $recv2 <> "" Then
        $ret = TCPSend($ConnectedSocket1[$Track], $recv2)
        EndIf

;~         If $ConnectedSocket1[$Track] = -1 Then
;~         TCPCloseSocket($ConnectedSocket1[$Track])
;~         Add_msg("User disconected " & SocketToIP($ConnectedSocket2[$Track]))
;~         EndIf
    EndIf

Next

WEnd

;~ 192.168.1.135





;~     Add_msg("Shudown..")
;~     TCPShutdown()
EndFunc  ;==>Example


Func find_vnc($SHOCKET)
    Local $Trackm
For $Trackm=1 to $vnc_servers_tmp[0] Step 1
    if $vnc_servers[$Trackm][1] = -1 Then
    $vnc_servers[$Trackm][1] = $SHOCKET
    Return $vnc_servers[$Trackm][0]
    EndIf
Next

EndFunc




Func openSocket($SHOCKETm)
    Local $iIndex , $Trackg
        write_log("User disconected Socket: " &$SHOCKETm& " IP: "& SocketToIP($ConnectedSocket1[$SHOCKETm]))
    TCPCloseSocket($ConnectedSocket2[$SHOCKETm])
    TCPCloseSocket($ConnectedSocket1[$SHOCKETm])
        $ConnectedSocket1[$SHOCKETm] = -1
        $ConnectedSocket2[$SHOCKETm] = -1

For $Trackg = 1 to UBound($vnc_servers)-1
            ;ConsoleWrite("Track: "&$Trackg&"  "&$vnc_servers[$Trackg][1] &" = "& $SHOCKETm &""&@CRLF)
    If $vnc_servers[$Trackg][1] = $SHOCKETm Then

        $vnc_servers[$Trackg][1] = -1
        $gui_display[$Trackg][2] = ""
        $gui_display[$Trackg][3] = ""
;~      Break
    EndIf

Next


;~     $iIndex = _ArraySearch($vnc_servers, $SHOCKETm, 0, 0, 0, 1, 1)
;~     If @error Then
;~         Add_msg("Cand find server to free up for disconected socket" & $SHOCKETm)
;~     Else
;~         $vnc_servers[$iIndex][1] = -1
;~         Add_msg("Server sucesfuly found VNC server to free up for disconected socket" & $SHOCKETm)
;~      Add_msg("Array NO: " & $iIndex)
;~     EndIf

EndFunc

Func Scan_sockets()
;~     Add_msg("Socket scandig start")
;~     Local $ret1, $ret2, $Trackp
;~  Global $vnc_servers
;~     For $Trackp = 0 To $MaxConnection Step 1
;~     if $ConnectedSocket1[$Trackp] <> -1 Then
;~      $ret1 = TCPSend($ConnectedSocket1[$Trackp], "")
;~      $ret1 = TCPRecv($ConnectedSocket1[$Trackp], 0)
;~         Select
;~          Case @error
;~              openSocket($Trackp)
;~          Case $ret1 < 0
;~              openSocket($Trackp)
;~      EndSelect

;~      $ret2 = TCPSend($ConnectedSocket2[$Trackp], "")
;~      $ret2 = TCPRecv($ConnectedSocket2[$Trackp], "")
;~         Select
;~          Case @error
;~              openSocket($Trackp)
;~          Case $ret2 < 0
;~              openSocket($Trackp)
;~      EndSelect
;~     EndIf
;~ $len1 = StringLen($ret1)
;~ $len2 = StringLen($ret2)

;~ $len1 = BinaryLen($ret1)
;~ $len2 = BinaryLen($ret2)
;~ $srv_arr_id = Get_srv_id($Trackp)
;~ $vnc_servers[$srv_arr_id][2] = $len1
;~ $vnc_servers[$srv_arr_id][3] = $len2

;~ Add_msg("LEN1: "& $len1 & "    LEN2: "&$len2)
;~  Next
;~     Add_msg("Socket scandig end")
EndFunc

Func Get_srv_id($SHOCKETmm)
;~  Local $SHOCKETmm, $Trackgg
    For $Trackgg = 1 to UBound($vnc_servers)-1
    If $vnc_servers[$Trackgg][1] = $SHOCKETmm Then
        Return $Trackgg
;~      Break
    EndIf

Next
EndFunc


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    Local $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc  ;==>SocketToIP

;Function to add text to gui text area
;----------------------------------------------------------------------
Func Add_msg($msg)
    Global $edit
    GUICtrlSetData($edit, _NowTime() & " >  " & $msg & @CRLF & GUICtrlRead($edit))
EndFunc;==>Add_msg

Func write_log($log)
_FileWriteLog(@ScriptDir & "\" & @YEAR & @MON & @MDAY & ".log",$log)

EndFunc

Func SocketSearch()
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket1[$Track] = -1 Then Return $Track
    Next
EndFunc  ;==>SocketSearch

Func Gui_update()
    Scan_sockets()
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView)); items added with UDF function can be deleted using UDF function
    _GUICtrlListView_AddArray($hListView, $gui_display)
EndFunc

;mattches ip A_ip is with wild card or simple
;B_ip is given ip
;if ip matches returns 1 if not returns -1
Func Match_ip($a_ip, $b_ip)
$a_arr = StringSplit($a_ip,".")
$b_arr = StringSplit($b_ip,".")
$Ret = 0

        if $a_arr[1] <> "*" Then
        if $a_arr[1] <> $b_arr[1] Then
            $Ret = -1
        EndIf
    EndIf

        if $a_arr[2] <> "*" Then
        if $a_arr[2] <> $b_arr[2] Then
            $Ret = -1
        EndIf
    EndIf


        if $a_arr[3] <> "*" Then
        if $a_arr[3] <> $b_arr[3] Then
            $Ret = -1
        EndIf
    EndIf

        if $a_arr[4] <> "*" Then
        if $a_arr[4] <> $b_arr[4] Then
            $Ret = -1
        EndIf
    EndIf

If $Ret = -1 Then
    SetError(1)
EndIf

Return $Ret
EndFunc


Func match_ip_array($ip_array, $ip)
For $x=1 to UBound($ip_array)-1
$check = Match_ip($ip_array[$x], $ip)
if Not @error Then
    Return 1
EndIf
Next
SetError(1)
$err = -1
Return $err

EndFunc

Share this post


Link to post
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

×