Jump to content

Serverless UDP


CodyBarrett
 Share

Recommended Posts

I'm curious if someone has done this before, i know many people have made Serverless UDP scripts, and MANY MORE have made MultisClient TCP Servers... but this? i've not come across this yet.

my concept:

one script per machine.

has a list of every IP that has that script, and which LAN its connecting to on your machine. here are some images of a concept design i showed to a buddy last semester (i appologize if anything is hard to read, or see.).

Please, if my knowledge of TCP\IP\UDP is wrong correct me. i want to make it right. And if you find any Bugs let me know! But most of all, :graduated: tell me what you think!

EDIT: you will need some UDFs that aren't standard. Thanks To MELBA23 for his help on this part!!

DIRECT LINK

Opt ('GUIONEVENTMODE',1)
#include <WINAPI.au3>
#Include <GuiMenu.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Include <GuiEdit.au3>
#include <misc.au3>
#include <array.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

#include "GUIScrollbars_Size.au3"
#include "GUIScrollbars_EX.au3"

_Singleton (@ScriptName)
;This VAR is a REGKEY with elements that contain all connected and enabled NICs, functional and nonfunctional.
Global $NetworkCards = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'
;-----------------------------------------------------------------------------------------------------------
Global $WIDTH = @DesktopWidth/2
Global $HEIGHT = @DesktopHeight/2
Global $buttonheight = 25
Dim $id_TreeView
Dim $hWnd_TreeView
Dim $UDP
Global $hMain = CreateMainGUI (@ScriptName,$WIDTH,$HEIGHT)
Global $NIC_Count = GetNICCount ()

If $NIC_Count >= 1 Then
    Dim $GUID_KEY_ARRAY[$NIC_Count+1] ;1-based array, Containing each NIC's unique ID.
    $GUID_KEY_ARRAY[0] = $NIC_Count

    Dim $GUID_TreeView_ID[$NIC_Count+1][3] ;1-based array, Containing Each NIC Treeview Item and its 2 children.
    $GUID_TreeView_ID[0][0] = $hWnd_TreeView

    Dim $NIC_IP_LIST[$NIC_Count+1];1-based array, Containing Each NIC's IP List in string format.
    $NIC_IP_LIST[0] = $NIC_Count

    Dim $Network_Adapter_Info_Array[$NIC_Count+1][6] ;1-based array, Some Information That is Needed Taken From The RegKey for That NIC.
    $Network_Adapter_Info_Array[0][0] = $NIC_Count

    For $n = 1 To $NIC_Count
        $GUID_KEY_ARRAY[$n] = 0
        $GUID_TreeView_ID[$n][0] = 0
        $NIC_IP_LIST[$n] = 0
        For $u = 1 To $NIC_Count
            $Network_Adapter_Info_Array[$n][$u] = 0
        Next
    Next

    Global $UDP = UDPStartup ()
    If @error <> 0 Then Exit

    For $n = 1 To $NIC_Count
        Startup_Every_NIC ($n)
    Next
Else
    MsgBox (48,'ERROR','No Networking Interface Cards Are Present.',Default,WinGetHandle ('[active]'))
    _Exit ()
EndIf


GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
AdlibRegister ('BroadCastToALL',1000)
AdlibRegister ('ReceiveData')


Do
    Sleep (100)
Until Not WinExists ($hMain)
_Exit ()


Func CreateMainGUI ($title,$w,$h)
    Local $hwnd,$cw, $ch,$th, $x,$y, $bw,$CtrlID
    $hwnd = GUICreate ($title,$w,$h)
        SetWindowColors ($hwnd)
        GUISetOnEvent (-3,'CloseWindow',$hwnd)
        GUISetState (@SW_SHOW,$hwnd)
    $x = 0
    $y = $buttonheight*2
    $cw = _WinAPI_GetClientWidth ($hwnd)
    $ch = _WinAPI_GetClientHeight ($hwnd)
    $th = $ch-($buttonheight*2)

    $CtrlID = GUICtrlCreateLabel ('Select An IP under IP Listings, and choose one of these options below.',0,0,$cw,$buttonheight)

    $bw = $cw/5
    $CtrlID = GUICtrlCreateButton ('Chat',0,$buttonheight,$bw,$buttonheight)
        GUICtrlSetOnEvent ($CtrlID,'ClickedChat')
    $CtrlID = GUICtrlCreateButton ('unknown',$bw,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*2,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*3,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*4,$buttonheight,$bw,$buttonheight)
    Global $id_TreeView = GUICtrlCreateTreeView ($x,$y,$cw,$th)
    Global $hWnd_TreeView = GUICtrlGetHandle ($id_TreeView)
    _GUICtrlTreeView_SetIcon($hWnd_TreeView, Default,@SystemDir & '\Shell32.dll',12) ;Sets the Default ICON to the hardware CHIP.
    Return $hwnd
EndFunc
Func GetNICCount ()
    Local $n = 0
    While 1
        $n += 1
        If RegEnumKey ($NetworkCards,$n) = '' Then Return $n - 1
    WEnd
EndFunc
Func ReceiveData ()
    Local $n, $data
    For $n = 1 To $NIC_Count ;making a loop for EACH NIC.
        If $Network_Adapter_Info_Array[$n][4] = -1 Then ;This is the socket that is created as a listening socket on the local IP for Each NIC.
            ContinueLoop
        Else
            $data = UDPRecv ($Network_Adapter_Info_Array[$n][4],1024)
            If @error Then
                If -1 >= @error >= -3 Then $data = $GUID_KEY_ARRAY[$n] & @CRLF & '[recv]Invalid SOCKETARRAY'
                MsgBox (48,'ERROR','ERROR-CODE=' & @error & @CRLF & $data,10,WinGetHandle ('[active]'))
            Else
                Select
                    Case StringLeft ($data,StringLen ('[online]=')) == '[online]='
                        RCVOnline ($n,StringTrimLeft ($data,StringLen ('[online]=')))


                    Case StringLeft ($data,StringLen ('[offline]=')) == '[offline]='
                        RCVOffline ($n,StringTrimLeft ($data,StringLen ('[offline]=')))


                    Case StringLeft ($data,StringLen ('[msg]=')) == '[msg]='
                        RCVNewMessage ($n,$data)


                    Case Else
                        ContinueLoop
                EndSelect
            EndIf
        EndIf
    Next
EndFunc
Func RCVOnline ($Instance,$IP)
    Local $hwnd
    If $IP <> $Network_Adapter_Info_Array[$Instance][1] Then ;IF the connecting IP isn't the same as the Current NIC's IP (YOUR LOCAL IP).
        If StringInStr ($NIC_IP_LIST[$Instance],'[' & $IP & ']') = 0 Then ;Checks if a duplicate IP is there.
            $NIC_IP_LIST[$Instance] &= '[' & $IP & ']';Adds it too the list for the specific IP.
            $hwnd = _GUICtrlTreeView_AddChild($hWnd_TreeView,$GUID_TreeView_ID[$Instance][2],$IP) ;Creates A Treeview Item under the NIC's IP Listing.
            _GUICtrlTreeView_SetIcon($hWnd_TreeView,$hwnd,@SystemDir & '\Shell32.dll',15)
        EndIf
    EndIf
EndFunc
Func RCVOffline ($Instance,$IP)
    _Exit () ;default, i'm not sure what i'm going to do here.
;~  If $data <> $Network_Adapter_Info_Array[$n][1] Then
;~      If StringInStr ($NIC_IP_LIST[$n],'[' & $data & ']') Then
;~          $NIC_IP_LIST[$n] = StringReplace ($NIC_IP_LIST[$n],'[' & $data & ']','')
;~          ;========================
;~          ;NEED TO FIND OUT HOW TO DELETE THE TREEV IITEM
;~          ;========================
;~      EndIf
;~  EndIf
EndFunc
Func RCVNewMessage ($Instance,$Data)
    Local $array, $TO,$msg,$FROM, $string, $stringlen
    $stringlen = StringLen ('[msg]=')
    $string = StringTrimLeft ($data,$stringlen)
    $array = StringSplit ($string,Chr (31))
    ;An Array is supposed to look like this
    ;----------------------------------------------
    ;[msg]=TOIP & CHR(31) & msg & CHR(31) & FROMIP
    ;----------------------------------------------
    If IsArray ($array) Then
        If UBound ($array) = 4 Then
            $TO = $array[1]
            $msg = $array[2]
            $FROM = $array[3]
            If $Network_Adapter_Info_Array[$Instance][1] = $TO Then Addmessage ($FROM,$Msg,$FROM) ;If THEY send it to THEIR chat window on YOUR Computer.
        EndIf
    EndIf
EndFunc
Func GetCtrlCount($hwnd,$Class)
    Local $count = 0
    While 1
        $count += 1
        If ControlGetHandle($hwnd, '', $Class & $count) = '' Then Return $count - 1
    WEnd
EndFunc
Func GetLastMessageIP ($hwnd)
    Local $string, $strinstr
    ;Message Posts Are Supposed To Look Like This
    ;----------------------------------------------
    ;IP Says:
    ;>>>>   ......
    ;----------------------------------------------
    ;This Gets the Character Position of the space between the IP and SAYS: returns IP
    $string = ControlGetText ($hwnd,'','Edit' & GetCtrlCount ($hwnd,'Edit'))
    $strinstr = StringInStr ($string,' ')
    If $strinstr > 0 Then Return StringMid ($string,1,$strinstr-1)
EndFunc
Func Addmessage ($TO,$msg,$FROM)
    Local $hwnd,$x,$y,$w,$h,$aRet, $CtrlID, $n, $cw, $ch
    If Not WinExists ($TO) Then CreateNewWindow ($TO)
    $msg =  @CRLF & '>>>' & @TAB  & $msg & @CRLF
    $hwnd = WinGetHandle ($TO&'SCROLL')
    $cw = _WinAPI_GetClientWidth($hwnd)
    $ch = _WinAPI_GetClientHeight($hwnd)
    $x = $buttonheight
    $y = $buttonheight + GetCtrlCount ($hwnd,'Edit') * ($buttonheight*4) ;Gets How Many Edit's there are, and multiplies it by a height for a total.
    $w = $cw-($x*2)
    $h = $buttonheight*3

    GUISwitch ($hwnd)
    If GetCtrlCount ($hwnd,'Edit') >= 1 Then
        If GetLastMessageIP ($hwnd) == $FROM Then ;To Continue The Last Post With The Last Poster.
            $ehwnd = ControlGetHandle ($hwnd,'','Edit' & GetCtrlCount ($hwnd,'Edit'))
        Else
            _GUIScrollBars_SetScrollInfoPos($hwnd, $SB_VERT, 0) ;Scrolls To Begining
            $CtrlID = GUICtrlCreateEdit ('',$x,$y,$w,$h,BitOR ($ES_READONLY,$WS_TABSTOP,$WS_VSCROLL))
            $ehwnd = GUICtrlGetHandle ($CtrlID)
            $msg = $FROM & ' Says:' & $msg
            If  $TO == $FROM Then GUICtrlSetBkColor ($CtrlID,0xFEDCBA)

            ;Sets New Size Of Window and Scrolls To New position.
            ;-------------------------------------------
            If $y+$h > _WinAPI_GetClientHeight($hwnd) Then
                $aRet = _GUIScrollbars_Size(0, $y+$h,$cw,$ch)
                _GUIScrollBars_SetScrollInfoPage($hwnd, $SB_VERT, $aRet[2])
                _GUIScrollBars_SetScrollInfoMax($hwnd, $SB_VERT, $aRet[3])
                _GUIScrollBars_SetScrollInfoPos($hWnd, $SB_VERT,_GUIScrollBars_GetScrollInfoMax ($hwnd,$SB_VERT))
            EndIf
            ;-------------------------------------------
        EndIf
    Else
        $CtrlID = GUICtrlCreateEdit ('',$x,$y,$w,$h,BitOR ($ES_READONLY,$WS_TABSTOP,$WS_VSCROLL))
        $ehwnd = GUICtrlGetHandle ($CtrlID)
        $msg = $FROM & ' Says:' & $msg
        If  $TO == $FROM Then GUICtrlSetBkColor ($CtrlID,0xFEDCBA)
    EndIf
    _GUICtrlEdit_AppendText($ehwnd,$msg)
    SetFocus ($TO)
EndFunc
Func SetFocus ($IP)
    If WinActive ($IP) Or WinActive ($IP&'SCROLL') Or WinActive ($IP&'INPUT') Then
        $hwnd = ControlGetHandle ($IP&'INPUT','','Edit1')
        $CtrlID = _WinAPI_GetDlgCtrlID ($hwnd)
        GUICtrlSetState ($CtrlID,256)
    EndIf
EndFunc
Func BroadCastToALL ()
    Local $n
    For $n = 1 To $NIC_Count
        If $Network_Adapter_Info_Array[$n][5] = -1 Then
            ContinueLoop
        Else
            ;BroadCasts the NIC's IPAddress, To The NIC's BROADCAST IP.
            ;-------------------------------------------
            UDP_Send ($Network_Adapter_Info_Array[$n][5],'[online]=' & $Network_Adapter_Info_Array[$n][1])
            ;-------------------------------------------
        EndIf
    Next
EndFunc
Func UDP_Send ($socket_array,$msg)
    UDPSend ($socket_array,$msg)
    If @error Then MsgBox (48,'ERROR','UDP_Send:'& @error & @CR & $msg,10,WinGetHandle ('[active]'))
EndFunc
Func ClickedChat ()
    Local $thWnd, $tphWnd,$text,$IP, $array
    $thWnd = _GUICtrlTreeView_GetSelection($hWnd_TreeView)
    $tphWnd = _GUICtrlTreeView_GetParentHandle($hWnd_TreeView, $thWnd)
    If _GUICtrlTreeView_GetText($hWnd_TreeView,$tphWnd) == 'IP Listing' Then
    ;-------------------------------------------
    ;IP LISTING
    ;------IP1
    ;------IP2
    ;------IPn
        $IP = _GUICtrlTreeView_GetText($hWnd_TreeView,$thWnd)
    ;-------------------------------------------
        CreateNewWindow ($IP)
    EndIf
EndFunc
Func buttonSendMessage ()
    Local $IP, $msg, $n,$Socket
    $IP = WinGetTitle (_WinAPI_GetParent (@GUI_WinHandle))
    $Msg = ControlGetText (@GUI_WinHandle,'','Edit1')
    ControlSetText (@GUI_WinHandle,'','Edit1','')
    For $n = 1 To $NIC_Count
        If StringInStr ($NIC_IP_LIST[$n],'[' & $IP & ']') Then
            $Socket = UDPOpen ($Ip,$Network_Adapter_Info_Array[$n][3]) ;Opens A Specific SOCKET for sending to a specific client.
            If @error Then
                MsgBox (48,'ERROR','ERROR-CODE=' & @error,10,WinGetHandle ('[active]'))
            Else
                UDP_Send ($Socket,'[msg]=' & $IP & Chr (31) & $Msg & Chr (31) & $Network_Adapter_Info_Array[$n][1])
                If @error Then
                    $msg = ''
                    If -1 >= @error >= -3 Then $msg = 'INVALID SOCKET ARRAY'
                    If @error = 1 Then $Msg = 'INVALID IP'
                    If @error = 2 Then $Msg = 'INVALID PORT'
                    MsgBox (48,'ERROR','ERROR-CODE=' & @error & @CRLF & $GUID_KEY_ARRAY[$n] & @CRLF & $msg,10,WinGetHandle ('[active]'))
                Else
                    Addmessage ($IP,$msg,$Network_Adapter_Info_Array[$n][1])
                EndIf
            EndIf
            UDPCloseSocket ($Socket) ;closes the specific socket.
            Return
        EndIf
    Next
EndFunc
Func SetWindowColors ($hwnd)
    GUISetBkColor (0xABCDEF,$hwnd)
    GUICtrlSetDefColor (0xFFFFFF,$hwnd)
    GUICtrlSetDefBkColor (0xABCDEF,$hwnd)
    GUISetFont (10,999,'','Tahoma',$hwnd)
EndFunc
Func CreateNewWindow ($title)
    Local $wp, $hp, $parent, $x,$y,$w,$h,$child_input,$child_scroll,$aRet, $CtrlID, $cw, $ch
    If WinExists ($title) Then Return
    $wp = @DesktopWidth/2
    $hp = @DesktopHeight/2
    $parent = GUICreate ($title,$wp,$hp,Default,Default,$WS_POPUPWINDOW)
    $cw = _WinAPI_GetClientWidth ($parent)
    $ch = _WinAPI_GetClientHeight ($parent)
        SetWindowColors ($parent)
        GUISetOnEvent (-3,'CloseWindow',$parent)
            $CtrlID = GUICtrlCreateLabel ($title,0,0,$wp-$buttonheight*2,$hp,Default,0x00100000)
            $CtrlID = GUICtrlCreateLabel ('CLOSE',$wp-$buttonheight*2,0,$buttonheight*2,$buttonheight,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
                GUICtrlSetOnEvent ($CtrlID,'CloseWindow')
                GUICtrlSetCursor ($CtrlID,0)
            $CtrlID = GUICtrlCreateLabel ('',$wp-$buttonheight*2,$buttonheight,$buttonheight*2,$hp-$buttonheight,Default,0x00100000)
    ;--------------------------------------------------------------------------------------------------------------------
    ;THIS makes a child window, specifically for scrolling through posts between two people.
        $x = $buttonheight/2
        $y = $buttonheight*2.5
        $w = $cw-$buttonheight
        $h = ($ch-($buttonheight*5.5))
            $child_scroll = GUICreate ($title&'SCROLL',$w,$h,$x,$y,$WS_POPUPWINDOW,$WS_EX_MDICHILD,$parent)
            SetWindowColors ($child_scroll)

            _GUIScrollBars_Init($child_scroll)
            $aRet = _GUIScrollbars_Size(0, $h, $w, $h)
            _GUIScrollBars_ShowScrollBar($child_scroll, $SB_HORZ, False)
            _GUIScrollBars_SetScrollInfoPage($child_scroll, $SB_VERT, $aRet[2])
            _GUIScrollBars_SetScrollInfoMax($child_scroll, $SB_VERT, $aRet[3])
    ;--------------------------------------------------------------------------------------------------------------------
    ;THIS creates a child window to SEND messages to the other person
            $x = $buttonheight/2
            $y = $h+($buttonheight*3)
            $w = $cw-$buttonheight
            $h = $buttonheight*2
                    $child_input = GUICreate ($title&'INPUT',$w,$h,$x,$y,$WS_POPUPWINDOW,$WS_EX_MDICHILD,$parent)
                    SetWindowColors ($child_input)
            $x = 0
            $y = 0
            $w = $buttonheight * 2
            $h = $buttonheight * 2
            $cw = _WinAPI_GetClientWidth ($child_input)
            $ch = _WinAPI_GetClientHeight ($child_input)
                        $CtrlID = GUICtrlCreateButton ('Send',$cw-$w,0,$w,$h)
                            GUICtrlSetOnEvent ($CtrlID,'buttonSendMessage')
                        $CtrlID = GUICtrlCreateInput ('Type Here...',$x,$y,$cw-$w,$h,BitOR ($WS_VSCROLL,$ES_MULTILINE))
                            GUICtrlSetState ($CtrlID,256)


        GUISetState (@SW_SHOW, $parent)
        GUISetState (@SW_SHOW, $child_input)
        GUISetState (@SW_SHOW, $child_scroll)


;~      _WinAPI_SetWindowLong ($parent,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($parent,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetWindowLong ($child_scroll,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($child_scroll,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetWindowLong ($child_input,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($child_input,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetLayeredWindowAttributes ($parent,0xABCDEFa,170)
;~      _WinAPI_SetLayeredWindowAttributes ($child_scroll,0xABCDEFa,255)
;~      _WinAPI_SetLayeredWindowAttributes ($child_input,0xABCDEFa,255)
EndFunc
Func Startup_Every_NIC ($Instance)
    Local $Ip, $Port, $GUID, $SubnetMask, $Bind,$Open, $Interfaces, $Ip_Array,$Subnet_Array, $CtrlID, $n
    ;For Each Specified INSTANCE, This Gets The UNIQUE ID for the NIC
    ;-------------------------------------------
    $GUID = RegRead ($NetworkCards & RegEnumKey ($NetworkCards,$Instance),'ServiceName')
    $Interfaces = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\' & $GUID
    ;-------------------------------------------


    If RegRead ($Interfaces,'EnableDHCP') = Hex(1) Then ;If this uses a DHCP connection then it MUST use the DHCP IP and SUBNET
        $IPAddress = RegRead ($Interfaces,'DhcpIPAddress')
        If @error Then $IPAddress = RegRead ($Interfaces,'IPAddress') ;If it doesn't have an element for the IP then it uses the DEFAULT IP.
        $SubnetMask = RegRead ($Interfaces,'DhcpSubnetMask')
        If @error Then $SubnetMask = RegRead ($Interfaces,'SubnetMask') ;If it doesn't have an element for the SUBNET then it uses the DEFAULT SUBNET.
    Else
        $IPAddress = RegRead ($Interfaces,'IPAddress')
        $SubnetMask = RegRead ($Interfaces,'SubnetMask')
    EndIf


    ;splits the addresses into octets
    $Subnet_Array = StringSplit ($SubnetMask,'.')
    $Ip_Array = StringSplit ($IPAddress,'.')

    ;creates a broadcasting IP based on how many possible IPs are in the specified SUBNET.
    For $n = 1 To 4
        $Ip_Array[$n] = BitAND ($Ip_Array[$n],$Subnet_Array[$n])
        If $Subnet_Array[$n] = 0 Then $Ip_Array[$n] = '255'
    Next
    $Ip = $Ip_Array[1] & '.' & $Ip_Array[2] & '.' & $Ip_Array[3] & '.' & $Ip_Array[4]


    $Port = 49150
    $GUID_KEY_ARRAY[$Instance] = $GUID
    $NIC_IP_LIST[$Instance] = $GUID


    $Network_Adapter_Info_Array[$Instance][0] = $SubnetMask
    $Network_Adapter_Info_Array[$Instance][1] = $IPAddress
    $Network_Adapter_Info_Array[$Instance][2] = $Ip
    $Network_Adapter_Info_Array[$Instance][3] = $Port


    If $Network_Adapter_Info_Array[$Instance][0] == '0.0.0.0' Or  $Network_Adapter_Info_Array[$Instance][1] == '0.0.0.0' Then
        $Bind = -1 ;NON FUNCTIONAL NIC
        $Open = -1 ;NON FUNCTIONAL NIC
    Else
        $Bind = UDPBind ($Network_Adapter_Info_Array[$Instance][1],$Network_Adapter_Info_Array[$Instance][3])
        If @error Then $Bind = -1 ;NON FUNCTIONAL NIC
        $Open = UDPOpen ($Network_Adapter_Info_Array[$Instance][2],$Network_Adapter_Info_Array[$Instance][3])
        If @error Then $Open = -1 ;NON FUNCTIONAL NIC
    EndIf
    ;--------------------SERVER SOCKET, Opened On Local IP--------------------
        $Network_Adapter_Info_Array[$Instance][4] = $Bind
    ;----------------------------------------------------------------------
    ;--------------------BroadCasting Socket Opened On BroadCasting IP--------------------
        $Network_Adapter_Info_Array[$Instance][5] = $Open
    ;--------------------------------------------------------------------------------
        ;----------Create A ITEM for each NIC----------
        $GUID_TreeView_ID[$Instance][0] = _GUICtrlTreeView_Add ($hWnd_TreeView,0,$GUID_KEY_ARRAY[$Instance])
        If $Network_Adapter_Info_Array[$Instance][4] = -1 Or $Network_Adapter_Info_Array[$Instance][5] = -1 Then _GUICtrlTreeView_SetIcon($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],@SystemDir & '\Shell32.dll',109)
        ;--------------------------------------------------
            ;----------Creates Information For That NIC
            $GUID_TreeView_ID[$Instance][1] = _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],'Information')
                _GUICtrlTreeView_SetIcon($hWnd_TreeView, $GUID_TreeView_ID[$Instance][1],@SystemDir & '\Shell32.dll',54)
            ;----------------------------------------
            ;----------Subnet IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Subnet: '& $Network_Adapter_Info_Array[$Instance][0])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',18)
            ;------------------------------
            ;----------Local IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Local IP: '& $Network_Adapter_Info_Array[$Instance][1])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;------------------------------
            ;----------BroadCasting IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'BroadCasting IP: '& $Network_Adapter_Info_Array[$Instance][2])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;----------------------------------------
            ;----------Port number----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Port: '& $Network_Adapter_Info_Array[$Instance][3])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;------------------------------
            ;----------Creates An IP List----------
            $GUID_TreeView_ID[$Instance][2] = _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],'IP Listing')
                _GUICtrlTreeView_SetIcon($hWnd_TreeView, $GUID_TreeView_ID[$Instance][2],@SystemDir & '\Shell32.dll',17)
            ;----------------------------------------
    Return
EndFunc
Func CloseWindow ()
    GUIDelete (@GUI_WinHandle)
EndFunc
Func _Exit()
    Local $status, $n
    If $UDP = True Then
        For $n = 1 To $NIC_Count
            If $Network_Adapter_Info_Array[$n][5] <> -1 Then UDP_Send ($Network_Adapter_Info_Array[$n][5],'[offline]=' & $Network_Adapter_Info_Array[$n][1]) ;BroadCasts a goodbye Message.
            UDPCloseSocket ($Network_Adapter_Info_Array[$n][4])
            UDPCloseSocket ($Network_Adapter_Info_Array[$n][5])
        Next
        UDPShutdown()
    EndIf
    Exit
EndFunc

EDIT: cleaned up a few lines.

Edited by CodyBarrett
Link to comment
Share on other sites

I'm curious if someone has done this before, i know many people have made Serverless UDP scripts, and MANY MORE have made MultisClient TCP Servers... but this? i've not come across this yet.

my concept:

one script per machine.

has a list of every IP that has that script, and which LAN its connecting to on your machine. here are some images of a concept design i showed to a buddy last semester (i appologize if anything is hard to read, or see.).

Please, if my knowledge of TCP\IP\UDP is wrong correct me. i want to make it right. And if you find any Bugs let me know! But most of all, :graduated: tell me what you think!

Opt ('GUIONEVENTMODE',1)
#include <WINAPI.au3>
#Include <GuiMenu.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Include <GuiEdit.au3>
#include <misc.au3>
#include <array.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

#include "GUIScrollbars_Size.au3"
#include "GUIScrollbars_EX.au3"

_Singleton (@ScriptName)
;This VAR is a REGKEY with elements that contain all connected and enabled NICs, functional and nonfunctional.
Global $NetworkCards = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'
;-----------------------------------------------------------------------------------------------------------
Global $WIDTH = @DesktopWidth/2
Global $HEIGHT = @DesktopHeight/2
Global $buttonheight = 25
Dim $id_TreeView
Dim $hWnd_TreeView
Dim $UDP
Global $hMain = CreateMainGUI (@ScriptName,$WIDTH,$HEIGHT)
Global $NIC_Count = GetNICCount ()

If $NIC_Count >= 1 Then
    Dim $GUID_KEY_ARRAY[$NIC_Count+1] ;1-based array, Containing each NIC's unique ID.
    $GUID_KEY_ARRAY[0] = $NIC_Count

    Dim $GUID_TreeView_ID[$NIC_Count+1][3] ;1-based array, Containing Each NIC Treeview Item and its 2 children.
    $GUID_TreeView_ID[0][0] = $hWnd_TreeView

    Dim $NIC_IP_LIST[$NIC_Count+1];1-based array, Containing Each NIC's IP List in string format.
    $NIC_IP_LIST[0] = $NIC_Count

    Dim $Network_Adapter_Info_Array[$NIC_Count+1][6] ;1-based array, Some Information That is Needed Taken From The RegKey for That NIC.
    $Network_Adapter_Info_Array[0][0] = $NIC_Count

    For $n = 1 To $NIC_Count
        $GUID_KEY_ARRAY[$n] = 0
        $GUID_TreeView_ID[$n][0] = 0
        $NIC_IP_LIST[$n] = 0
        For $u = 1 To $NIC_Count
            $Network_Adapter_Info_Array[$n][$u] = 0
        Next
    Next

    Global $UDP = UDPStartup ()
    If @error <> 0 Then Exit

    For $n = 1 To $NIC_Count
        Startup_Every_NIC ($n)
    Next
Else
    MsgBox (48,'ERROR','No Networking Interface Cards Are Present.',Default,WinGetHandle ('[active]'))
    _Exit ()
EndIf


GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
AdlibRegister ('BroadCastToALL',1000)
AdlibRegister ('ReceiveData')


Do
    Sleep (100)
Until Not WinExists ($hMain)
_Exit ()


Func CreateMainGUI ($title,$w,$h)
    Local $hwnd,$cw, $ch,$th, $x,$y, $bw,$CtrlID
    $hwnd = GUICreate ($title,$w,$h)
        SetWindowColors ($hwnd)
        GUISetOnEvent (-3,'CloseWindow',$hwnd)
        GUISetState (@SW_SHOW,$hwnd)
    $x = 0
    $y = $buttonheight*2
    $cw = _WinAPI_GetClientWidth ($hwnd)
    $ch = _WinAPI_GetClientHeight ($hwnd)
    $th = $ch-($buttonheight*2)

    $CtrlID = GUICtrlCreateLabel ('Select An IP under IP Listings, and choose one of these options below.',0,0,$cw,$buttonheight)

    $bw = $cw/5
    $CtrlID = GUICtrlCreateButton ('Chat',0,$buttonheight,$bw,$buttonheight)
        GUICtrlSetOnEvent ($CtrlID,'ClickedChat')
    $CtrlID = GUICtrlCreateButton ('unknown',$bw,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*2,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*3,$buttonheight,$bw,$buttonheight)
    $CtrlID = GUICtrlCreateButton ('unknown',$bw*4,$buttonheight,$bw,$buttonheight)
    Global $id_TreeView = GUICtrlCreateTreeView ($x,$y,$cw,$th)
    Global $hWnd_TreeView = GUICtrlGetHandle ($id_TreeView)
    _GUICtrlTreeView_SetIcon($hWnd_TreeView, Default,@SystemDir & '\Shell32.dll',12) ;Sets the Default ICON to the hardware CHIP.
    Return $hwnd
EndFunc
Func GetNICCount ()
    Local $n = 0
    While 1
        $n += 1
        If RegEnumKey ($NetworkCards,$n) = '' Then Return $n - 1
    WEnd
EndFunc
Func ReceiveData ()
    Local $n, $data
    For $n = 1 To $NIC_Count ;making a loop for EACH NIC.
        If $Network_Adapter_Info_Array[$n][4] = -1 Then ;This is the socket that is created as a listening socket on the local IP for Each NIC.
            ContinueLoop
        Else
            $data = UDPRecv ($Network_Adapter_Info_Array[$n][4],1024)
            If @error Then
                If -1 >= @error >= -3 Then $data = $GUID_KEY_ARRAY[$n] & @CRLF & '[recv]Invalid SOCKETARRAY'
                MsgBox (48,'ERROR','ERROR-CODE=' & @error & @CRLF & $data,10,WinGetHandle ('[active]'))
            Else
                Select
                    Case StringLeft ($data,StringLen ('[online]=')) == '[online]='
                        RCVOnline ($n,StringTrimLeft ($data,StringLen ('[online]=')))


                    Case StringLeft ($data,StringLen ('[offline]=')) == '[offline]='
                        RCVOffline ($n,StringTrimLeft ($data,StringLen ('[offline]=')))


                    Case StringLeft ($data,StringLen ('[msg]=')) == '[msg]='
                        RCVNewMessage ($n,$data)


                    Case Else
                        ContinueLoop
                EndSelect
            EndIf
        EndIf
    Next
EndFunc
Func RCVOnline ($Instance,$IP)
    Local $hwnd
    If $IP <> $Network_Adapter_Info_Array[$Instance][1] Then ;IF the connecting IP isn't the same as the Current NIC's IP (YOUR LOCAL IP).
        If StringInStr ($NIC_IP_LIST[$Instance],'[' & $IP & ']') = 0 Then ;Checks if a duplicate IP is there.
            $NIC_IP_LIST[$Instance] &= '[' & $IP & ']';Adds it too the list for the specific IP.
            $hwnd = _GUICtrlTreeView_AddChild($hWnd_TreeView,$GUID_TreeView_ID[$Instance][2],$IP) ;Creates A Treeview Item under the NIC's IP Listing.
            _GUICtrlTreeView_SetIcon($hWnd_TreeView,$hwnd,@SystemDir & '\Shell32.dll',15)
        EndIf
    EndIf
EndFunc
Func RCVOffline ($Instance,$IP)
    _Exit () ;default, i'm not sure what i'm going to do here.
;~  If $data <> $Network_Adapter_Info_Array[$n][1] Then
;~      If StringInStr ($NIC_IP_LIST[$n],'[' & $data & ']') Then
;~          $NIC_IP_LIST[$n] = StringReplace ($NIC_IP_LIST[$n],'[' & $data & ']','')
;~          ;========================
;~          ;NEED TO FIND OUT HOW TO DELETE THE TREEV IITEM
;~          ;========================
;~      EndIf
;~  EndIf
EndFunc
Func RCVNewMessage ($Instance,$Data)
    Local $array, $TO,$msg,$FROM, $string, $stringlen
    $stringlen = StringLen ('[msg]=')
    $string = StringTrimLeft ($data,$stringlen)
    $array = StringSplit ($string,Chr (31))
    ;An Array is supposed to look like this
    ;----------------------------------------------
    ;[msg]=TOIP & CHR(31) & msg & CHR(31) & FROMIP
    ;----------------------------------------------
    If IsArray ($array) Then
        If UBound ($array) = 4 Then
            $TO = $array[1]
            $msg = $array[2]
            $FROM = $array[3]
            If $Network_Adapter_Info_Array[$Instance][1] = $TO Then Addmessage ($FROM,$Msg,$FROM) ;If THEY send it to THEIR chat window on YOUR Computer.
        EndIf
    EndIf
EndFunc
Func GetCtrlCount($hwnd,$Class)
    Local $count = 0
    While 1
        $count += 1
        If ControlGetHandle($hwnd, '', $Class & $count) = '' Then Return $count - 1
    WEnd
EndFunc
Func GetLastMessageIP ($hwnd)
    Local $string, $strinstr
    ;Message Posts Are Supposed To Look Like This
    ;----------------------------------------------
    ;IP Says:
    ;>>>>   ......
    ;----------------------------------------------
    ;This Gets the Character Position of the space between the IP and SAYS: returns IP
    $string = ControlGetText ($hwnd,'','Edit' & GetCtrlCount ($hwnd,'Edit'))
    $strinstr = StringInStr ($string,' ')
    If $strinstr > 0 Then Return StringMid ($string,1,$strinstr)
EndFunc
Func Addmessage ($TO,$msg,$FROM)
    Local $hwnd,$x,$y,$w,$h,$aRet, $CtrlID, $n, $cw, $ch
    If Not WinExists ($TO) Then CreateNewWindow ($TO)
    $msg =  @CRLF & '>>>' & @TAB  & $msg & @CRLF
    $hwnd = WinGetHandle ($TO&'SCROLL')
    $cw = _WinAPI_GetClientWidth($hwnd)
    $ch = _WinAPI_GetClientHeight($hwnd)
    $x = $buttonheight
    $y = $buttonheight + GetCtrlCount ($hwnd,'Edit') * ($buttonheight*4) ;Gets How Many Edit's there are, and multiplies it by a height for a total.
    $w = $cw-($x*2)
    $h = $buttonheight*3

    GUISwitch ($hwnd)
    If GetCtrlCount ($hwnd,'Edit') >= 1 Then
        If GetLastMessageIP ($hwnd) == $FROM Then ;To Continue The Last Post With The Last Poster.
            $ehwnd = ControlGetHandle ($hwnd,'','Edit' & GetCtrlCount ($hwnd,'Edit'))
        Else
            _GUIScrollBars_SetScrollInfoPos($hwnd, $SB_VERT, 0) ;Scrolls To Begining
            $CtrlID = GUICtrlCreateEdit ('',$x,$y,$w,$h,BitOR ($ES_READONLY,$WS_TABSTOP,$WS_VSCROLL))
            $ehwnd = GUICtrlGetHandle ($CtrlID)
            $msg = $FROM & ' Says:' & $msg
            If  $TO == $FROM Then GUICtrlSetBkColor ($CtrlID,0xFEDCBA)

            ;Sets New Size Of Window and Scrolls To New position.
            ;-------------------------------------------
            If $y+$h > _WinAPI_GetClientHeight($hwnd) Then
                $aRet = _GUIScrollbars_Size(0, $y+$h,$cw,$ch)
                _GUIScrollBars_SetScrollInfoPage($hwnd, $SB_VERT, $aRet[2])
                _GUIScrollBars_SetScrollInfoMax($hwnd, $SB_VERT, $aRet[3])
                _GUIScrollBars_SetScrollInfoPos($hWnd, $SB_VERT,_GUIScrollBars_GetScrollInfoMax ($hwnd,$SB_VERT))
            EndIf
            ;-------------------------------------------
        EndIf
    Else
        $CtrlID = GUICtrlCreateEdit ('',$x,$y,$w,$h,BitOR ($ES_READONLY,$WS_TABSTOP,$WS_VSCROLL))
        $ehwnd = GUICtrlGetHandle ($CtrlID)
        $msg = $FROM & ' Says:' & $msg
        If  $TO == $FROM Then GUICtrlSetBkColor ($CtrlID,0xFEDCBA)
    EndIf
    _GUICtrlEdit_AppendText($ehwnd,$msg)
    SetFocus ($TO)
EndFunc
Func SetFocus ($IP)
    If WinActive ($IP) Or WinActive ($IP&'SCROLL') Or WinActive ($IP&'INPUT') Then
        $hwnd = ControlGetHandle ($IP&'INPUT','','Edit1')
        $CtrlID = _WinAPI_GetDlgCtrlID ($hwnd)
        GUICtrlSetState ($CtrlID,256)
    EndIf
EndFunc
Func BroadCastToALL ()
    Local $n
    For $n = 1 To $NIC_Count
        If $Network_Adapter_Info_Array[$n][5] = -1 Then
            ContinueLoop
        Else
            ;BroadCasts the NIC's IPAddress, To The NIC's BROADCAST IP.
            ;-------------------------------------------
            UDP_Send ($Network_Adapter_Info_Array[$n][5],'[online]=' & $Network_Adapter_Info_Array[$n][1])
            ;-------------------------------------------
        EndIf
    Next
EndFunc
Func UDP_Send ($socket_array,$msg)
    UDPSend ($socket_array,$msg)
    If @error Then MsgBox (48,'ERROR','UDP_Send:'& @error & @CR & $msg,10,WinGetHandle ('[active]'))
EndFunc
Func ClickedChat ()
    Local $thWnd, $tphWnd,$text,$IP, $array
    $thWnd = _GUICtrlTreeView_GetSelection($hWnd_TreeView)
    $tphWnd = _GUICtrlTreeView_GetParentHandle($hWnd_TreeView, $thWnd)
    If _GUICtrlTreeView_GetText($hWnd_TreeView,$tphWnd) == 'IP Listing' Then
    ;-------------------------------------------
    ;IP LISTING
    ;------IP1
    ;------IP2
    ;------IPn
        $IP = _GUICtrlTreeView_GetText($hWnd_TreeView,$thWnd)
    ;-------------------------------------------
        CreateNewWindow ($IP)
    EndIf
EndFunc
Func buttonSendMessage ()
    Local $IP, $msg, $n,$Socket
    $IP = WinGetTitle (_WinAPI_GetParent (@GUI_WinHandle))
    $Msg = ControlGetText (@GUI_WinHandle,'','Edit1')
    ControlSetText (@GUI_WinHandle,'','Edit1','')
    For $n = 1 To $NIC_Count
        If StringInStr ($NIC_IP_LIST[$n],'[' & $IP & ']') Then
            $Socket = UDPOpen ($Ip,$Network_Adapter_Info_Array[$n][3]) ;Opens A Specific SOCKET for sending to a specific client.
            If @error Then
                MsgBox (48,'ERROR','ERROR-CODE=' & @error,10,WinGetHandle ('[active]'))
            Else
                UDP_Send ($Socket,'[msg]=' & $IP & Chr (31) & $Msg & Chr (31) & $Network_Adapter_Info_Array[$n][1])
                If @error Then
                    $msg = ''
                    If -1 >= @error >= -3 Then $msg = 'INVALID SOCKET ARRAY'
                    If @error = 1 Then $Msg = 'INVALID IP'
                    If @error = 2 Then $Msg = 'INVALID PORT'
                    MsgBox (48,'ERROR','ERROR-CODE=' & @error & @CRLF & $GUID_KEY_ARRAY[$n] & @CRLF & $msg,10,WinGetHandle ('[active]'))
                Else
                    Addmessage ($IP,$msg,$Network_Adapter_Info_Array[$n][1])
                EndIf
            EndIf
            UDPCloseSocket ($Socket) ;closes the specific socket.
            Return
        EndIf
    Next
EndFunc
Func SetWindowColors ($hwnd)
    GUISetBkColor (0xABCDEF,$hwnd)
    GUICtrlSetDefColor (0xFFFFFF,$hwnd)
    GUICtrlSetDefBkColor (0xABCDEF,$hwnd)
    GUISetFont (10,999,'','Tahoma',$hwnd)
EndFunc
Func CreateNewWindow ($title)
    Local $wp, $hp, $parent, $x,$y,$w,$h,$child_input,$child_scroll,$aRet, $CtrlID, $cw, $ch
    If WinExists ($title) Then Return
    $wp = @DesktopWidth/2
    $hp = @DesktopHeight/2
    $parent = GUICreate ($title,$wp,$hp,Default,Default,$WS_POPUPWINDOW)
    $cw = _WinAPI_GetClientWidth ($parent)
    $ch = _WinAPI_GetClientHeight ($parent)
        SetWindowColors ($parent)
        GUISetOnEvent (-3,'CloseWindow',$parent)
            $CtrlID = GUICtrlCreateLabel ($title,0,0,$wp-$buttonheight*2,$hp,Default,0x00100000)
            $CtrlID = GUICtrlCreateLabel ('CLOSE',$wp-$buttonheight*2,0,$buttonheight*2,$buttonheight,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
                GUICtrlSetOnEvent ($CtrlID,'CloseWindow')
                GUICtrlSetCursor ($CtrlID,0)
            $CtrlID = GUICtrlCreateLabel ('',$wp-$buttonheight*2,$buttonheight,$buttonheight*2,$hp-$buttonheight,Default,0x00100000)
    ;--------------------------------------------------------------------------------------------------------------------
    ;THIS makes a child window, specifically for scrolling through posts between two people.
        $x = $buttonheight/2
        $y = $buttonheight*2.5
        $w = $cw-$buttonheight
        $h = ($ch-($buttonheight*5.5))
            $child_scroll = GUICreate ($title&'SCROLL',$w,$h,$x,$y,$WS_POPUPWINDOW,$WS_EX_MDICHILD,$parent)
            SetWindowColors ($child_scroll)

            _GUIScrollBars_Init($child_scroll)
            $aRet = _GUIScrollbars_Size(0, $h, $w, $h)
            _GUIScrollBars_ShowScrollBar($child_scroll, $SB_HORZ, False)
            _GUIScrollBars_SetScrollInfoPage($child_scroll, $SB_VERT, $aRet[2])
            _GUIScrollBars_SetScrollInfoMax($child_scroll, $SB_VERT, $aRet[3])
    ;--------------------------------------------------------------------------------------------------------------------
    ;THIS creates a child window to SEND messages to the other person
            $x = $buttonheight/2
            $y = $h+($buttonheight*3)
            $w = $cw-$buttonheight
            $h = $buttonheight*2
                    $child_input = GUICreate ($title&'INPUT',$w,$h,$x,$y,$WS_POPUPWINDOW,$WS_EX_MDICHILD,$parent)
                    SetWindowColors ($child_input)
            $x = 0
            $y = 0
            $w = $buttonheight * 2
            $h = $buttonheight * 2
            $cw = _WinAPI_GetClientWidth ($child_input)
            $ch = _WinAPI_GetClientHeight ($child_input)
                        $CtrlID = GUICtrlCreateButton ('Send',$cw-$w,0,$w,$h)
                            GUICtrlSetOnEvent ($CtrlID,'buttonSendMessage')
                        $CtrlID = GUICtrlCreateInput ('Type Here...',$x,$y,$cw-$w,$h,BitOR ($WS_VSCROLL,$ES_MULTILINE))
                            GUICtrlSetState ($CtrlID,256)


        GUISetState (@SW_SHOW, $parent)
        GUISetState (@SW_SHOW, $child_input)
        GUISetState (@SW_SHOW, $child_scroll)


;~      _WinAPI_SetWindowLong ($parent,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($parent,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetWindowLong ($child_scroll,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($child_scroll,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetWindowLong ($child_input,$GWL_EXSTYLE,BitOR (_WinAPI_GetWindowLong ($child_input,$GWL_EXSTYLE),$WS_EX_LAYERED))
;~      _WinAPI_SetLayeredWindowAttributes ($parent,0xABCDEFa,170)
;~      _WinAPI_SetLayeredWindowAttributes ($child_scroll,0xABCDEFa,255)
;~      _WinAPI_SetLayeredWindowAttributes ($child_input,0xABCDEFa,255)
EndFunc
Func Startup_Every_NIC ($Instance)
    Local $Ip, $Port, $GUID, $SubnetMask, $Bind,$Open, $Interfaces, $Ip_Array,$Subnet_Array, $CtrlID, $n
    ;For Each Specified INSTANCE, This Gets The UNIQUE ID for the NIC
    ;-------------------------------------------
    $GUID = RegRead ($NetworkCards & RegEnumKey ($NetworkCards,$Instance),'ServiceName')
    $Interfaces = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\' & $GUID
    ;-------------------------------------------


    If RegRead ($Interfaces,'EnableDHCP') = Hex(1) Then ;If this uses a DHCP connection then it MUST use the DHCP IP and SUBNET
        $IPAddress = RegRead ($Interfaces,'DhcpIPAddress')
        If @error Then $IPAddress = RegRead ($Interfaces,'IPAddress') ;If it doesn't have an element for the IP then it uses the DEFAULT IP.
        $SubnetMask = RegRead ($Interfaces,'DhcpSubnetMask')
        If @error Then $SubnetMask = RegRead ($Interfaces,'SubnetMask') ;If it doesn't have an element for the SUBNET then it uses the DEFAULT SUBNET.
    Else
        $IPAddress = RegRead ($Interfaces,'IPAddress')
        $SubnetMask = RegRead ($Interfaces,'SubnetMask')
    EndIf


    ;splits the addresses into octets
    $Subnet_Array = StringSplit ($SubnetMask,'.')
    $Ip_Array = StringSplit ($IPAddress,'.')

    ;creates a broadcasting IP based on how many possible IPs are in the specified SUBNET.
    For $n = 1 To 4
        $Ip_Array[$n] = BitAND ($Ip_Array[$n],$Subnet_Array[$n])
        If $Subnet_Array[$n] = 0 Then $Ip_Array[$n] = '255'
    Next
    $Ip = $Ip_Array[1] & '.' & $Ip_Array[2] & '.' & $Ip_Array[3] & '.' & $Ip_Array[4]


    $Port = 49150
    $GUID_KEY_ARRAY[$Instance] = $GUID
    $NIC_IP_LIST[$Instance] = $GUID


    $Network_Adapter_Info_Array[$Instance][0] = $SubnetMask
    $Network_Adapter_Info_Array[$Instance][1] = $IPAddress
    $Network_Adapter_Info_Array[$Instance][2] = $Ip
    $Network_Adapter_Info_Array[$Instance][3] = $Port


    If $Network_Adapter_Info_Array[$Instance][0] == '0.0.0.0' And  $Network_Adapter_Info_Array[$Instance][1] == '0.0.0.0' Then
        $Bind = -1 ;NON FUNCTIONAL NIC
        $Open = -1 ;NON FUNCTIONAL NIC
    Else
        $Bind = UDPBind ($Network_Adapter_Info_Array[$Instance][1],$Network_Adapter_Info_Array[$Instance][3])
        If @error Then $Bind = -1 ;NON FUNCTIONAL NIC
        $Open = UDPOpen ($Network_Adapter_Info_Array[$Instance][2],$Network_Adapter_Info_Array[$Instance][3])
        If @error Then $Open = -1 ;NON FUNCTIONAL NIC
    EndIf
    ;--------------------SERVER SOCKET, Opened On Local IP--------------------
        $Network_Adapter_Info_Array[$Instance][4] = $Bind
    ;----------------------------------------------------------------------
    ;--------------------BroadCasting Socket Opened On BroadCasting IP--------------------
        $Network_Adapter_Info_Array[$Instance][5] = $Open
    ;--------------------------------------------------------------------------------
        ;----------Create A ITEM for each NIC----------
        $GUID_TreeView_ID[$Instance][0] = _GUICtrlTreeView_Add ($hWnd_TreeView,0,$GUID_KEY_ARRAY[$Instance])
        If $Network_Adapter_Info_Array[$Instance][4] = -1 Or $Network_Adapter_Info_Array[$Instance][5] = -1 Then _GUICtrlTreeView_SetIcon($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],@SystemDir & '\Shell32.dll',109)
        ;--------------------------------------------------
            ;----------Creates Information For That NIC
            $GUID_TreeView_ID[$Instance][1] = _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],'Information')
                _GUICtrlTreeView_SetIcon($hWnd_TreeView, $GUID_TreeView_ID[$Instance][1],@SystemDir & '\Shell32.dll',54)
            ;----------------------------------------
            ;----------Subnet IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Subnet: '& $Network_Adapter_Info_Array[$Instance][0])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',276)
            ;------------------------------
            ;----------Local IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Local IP: '& $Network_Adapter_Info_Array[$Instance][1])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;------------------------------
            ;----------BroadCasting IP----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'BroadCasting IP: '& $Network_Adapter_Info_Array[$Instance][2])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;----------------------------------------
            ;----------Port number----------
                    $CtrlID =  _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][1],'Port: '& $Network_Adapter_Info_Array[$Instance][3])
                        _GUICtrlTreeView_SetIcon($hWnd_TreeView,$CtrlID,@SystemDir & '\Shell32.dll',69)
            ;------------------------------
            ;----------Creates An IP List----------
            $GUID_TreeView_ID[$Instance][2] = _GUICtrlTreeView_AddChild ($hWnd_TreeView,$GUID_TreeView_ID[$Instance][0],'IP Listing')
                _GUICtrlTreeView_SetIcon($hWnd_TreeView, $GUID_TreeView_ID[$Instance][2],@SystemDir & '\Shell32.dll',281)
            ;----------------------------------------
    Return
EndFunc
Func CloseWindow ()
    GUIDelete (@GUI_WinHandle)
EndFunc
Func _Exit()
    Local $status, $n
    If $UDP = True Then
        For $n = 1 To $NIC_Count
            If $Network_Adapter_Info_Array[$n][5] <> -1 Then UDP_Send ($Network_Adapter_Info_Array[$n][5],'[offline]=' & $Network_Adapter_Info_Array[$n][1]) ;BroadCasts a goodbye Message.
            UDPCloseSocket ($Network_Adapter_Info_Array[$n][4])
            UDPCloseSocket ($Network_Adapter_Info_Array[$n][5])
        Next
        UDPShutdown()
    EndIf
    Exit
EndFunc

Sounds nice. Btw the concept you are talking about is called Peer to Peer (P2P). My favourite! By the look of things you are using what is called a large world network(correct me if im wrong), where everyone who you want to communicate with must be connected. It would be better if you create a system for messages to 'Hop' from node to node till they reach their destination, so instead of only being able to talk to say the 30 you are connect to, you can reach an unlimited number of nodes. Check out the Route_Message function in my P2P UDF if you don't know what I mean.

Tom.

Edited by hyperzap

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

well the thing is, this connection wouldn't really work through a gateway to the internet, i'd need a one server on the outside directly connected to the internet to connect every single network, i'll have to check later and see if i can incorporate a TRACERT command in there to gather router information for the LANs that i'm working with.

BTW your script looks good. i'll also have to look into it.

as of now, each client has a list of every network they are connected to, and they can only send packets to that network and the other people can only send packets on their network, i haven't gotten a PURE broadcast over multple NIC's yet.

i compiled it and tested on another machine i have, it gave me an error but doesn't give me an error on my current machine, do you guys get any error messages?

Link to comment
Share on other sites

I have these errors

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(14,10) : ERROR: can't open include file "GUIScrollbars_Size.au3"

#include "GUIScrollbars_Size.au3"

~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(15,10) : ERROR: can't open include file "GUIScrollbars_EX.au3"

#include "GUIScrollbars_EX.au3"

~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(64,53) : ERROR: _Scrollbars_WM_VSCROLL(): undefined function.

GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(223,61) : ERROR: _GUIScrollbars_Size(): undefined function.

$aRet = _GUIScrollbars_Size(0, $y+$h,$cw,$ch)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3 - 4 error(s), 0 warning(s)

Link to comment
Share on other sites

I have these errors

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(14,10) : ERROR: can't open include file "GUIScrollbars_Size.au3"

#include "GUIScrollbars_Size.au3"

~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(15,10) : ERROR: can't open include file "GUIScrollbars_EX.au3"

#include "GUIScrollbars_EX.au3"

~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(64,53) : ERROR: _Scrollbars_WM_VSCROLL(): undefined function.

GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3(223,61) : ERROR: _GUIScrollbars_Size(): undefined function.

$aRet = _GUIScrollbars_Size(0, $y+$h,$cw,$ch)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\Program Files\Ride Runner\Skins\Carwings_Dynamic_pm_new\Scripts\PouchinTV\toto.au3 - 4 error(s), 0 warning(s)

its because you need Melba23's scrollbar UDF

my apologies, here is the link to his topic:

Link to comment
Share on other sites

well the thing is, this connection wouldn't really work through a gateway to the internet, i'd need a one server on the outside directly connected to the internet to connect every single network, i'll have to check later and see if i can incorporate a TRACERT command in there to gather router information for the LANs that i'm working with.

BTW your script looks good. i'll also have to look into it.

as of now, each client has a list of every network they are connected to, and they can only send packets to that network and the other people can only send packets on their network, i haven't gotten a PURE broadcast over multple NIC's yet.

i compiled it and tested on another machine i have, it gave me an error but doesn't give me an error on my current machine, do you guys get any error messages?

You won't need a server on the outside to connect the network. What you would need is to port forward your router for every LAN network.

Instead of having a list of IP address (what happens if your IP addressing is dynamic) use this:

This is not a working hyperlink:

http://firenet-inttrk.appspot.com/trk/<tracker name>

so, you would call

Local $SOURCE = _INETGETSOURCE("http://firenet-inttrk.appspot.com/trk/serverlessudp?tick=1000&ip=" & @IPAddress1)

And that would retreieve a : separated list of IP's that accessed this URL within the last 1000 seconds, and add your @IPAddress1 to the list.

see http://firenet-inttrk.appspot.com/ for more info.

Btw a friend wrote this for my P2P Social networking program so credit must go to him.

-Tom.

This is the func in my script:

Func RUN_GROUP($NAME)
    GUICtrlSetData($COMMSTATUSLAB, "Status: Meshing")
    Local $SOURCE = _INETGETSOURCE("http://firenet-inttrk.appspot.com/trk/" & $NAME & "enc?tick=400&ip=" & _STRINGENCRYPT(1, @IPAddress1, "firenetip", 1))
    Local $CACHEDPEERS = StringSplit($SOURCE, ":", 1)
    Local $CONNECTLOOP = 15 - $TOTAL_CONNECTED_PEERS
    GUICtrlSetData($TOTALSTATUSLAB, "Total Online: " & $CACHEDPEERS[0])
    If $CONNECTLOOP > 0 Then
        For $LOOPX = 0 To $CONNECTLOOP Step 1
            $RND = Random(1, $CACHEDPEERS[0], 1)
            ConsoleWrite(@CRLF & "WEBCACHE RECORDS: " & $CACHEDPEERS[0])
            ConsoleWrite(@CRLF & "WEBCACHE: " & $CACHEDPEERS[$RND])
            _P2P_CONNECT(_STRINGENCRYPT(0, $CACHEDPEERS[$RND], "firenetip", 1))
        Next
    EndIf
    GUICtrlSetData($COMMSTATUSLAB, "Status: Running")
EndFunc
Edited by hyperzap

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

Hmm.. interesting. (trying to build P2P from scratch for my own personal knowledge)

i haven't figured out how to connect two LANs together if one of the PCs has multiple NICs and each NIC is connected to a different LAN, (technically) the LANs are connected, But they don't see eachother because of different hardware interfaces. I haven't figured out how to HOP packets over NICs and Between LANs. MOAR RESEARCH!!!

Link to comment
Share on other sites

Hmm.. interesting. (trying to build P2P from scratch for my own personal knowledge)

i haven't figured out how to connect two LANs together if one of the PCs has multiple NICs and each NIC is connected to a different LAN, (technically) the LANs are connected, But they don't see eachother because of different hardware interfaces. I haven't figured out how to HOP packets over NICs and Between LANs. MOAR RESEARCH!!!

Whats a NIC?

Secondly, I think your overcomplicating things;

1. To make a hop message thing first you give each node a unique identifier.

2.Then you get it to broadcast your 'hop' message to all whom you can talk to.

3. If those nodes you sent the message to are not the recipent of the message then get them to broadcast it to all they can talk to.

4. Do this for a maximun of 8 or so hops, to stop a loop of messages N1 -> N2 -> N3 -> N1 -> N2 etc

so it will stop after 8 broadcasts of your message.

That is the basis of a hop message system. Doesn't matter what network system your running, or its structure, as long as you can send data down it, it wil work.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

hmm.

a NIC is an Network Interface card, Each one has its own IP address. so if a computer has more than one NIC but each of them are on different LANs, my new goal is trying to send a message from one lan, to the computer with two+ NICs and that computer sends it to the specified IP on the LAN that is specified in the packet.

[example]

[NETWORK #1]

PC1 (one NIC)

PC2 (one NIC)

PC3 (two NICs)

[NETWORK #2]

PC1 (one NIC)

PC2 (one NIC)

PC3 (two NICs)

[NETWORK #3]

PC1 (one NIC)

PC2 (one NIC)

PC3 (one NIC)

NET#1 PC3 is connected both on NET#1 and NET#2

NET#2 PC3 is connected both on NET#2 and NET#3

NET#1 PC1 trys sending packet to NET#3 PC2, packet goes to NET#1 PC3 (cause it has two NICs) forwards it to NET#2 PC3 (cause it has two NICs) and then forwards it to NET#3 PC2

here is a drawn out version.

thats my dream atleast. to have every client script have a list of every single network they are capable of being connected to, and every ip on it. to have each client script act as both a User Interface on the surface, and a router running in the background. an OMNI connection.

EDIT: upon rethinking my goal, this idea could be a HUGE security risk if i were to bridge two LANs together without the user knowing. gonna have to make up another game plan.

Edited by CodyBarrett
Link to comment
Share on other sites

hmm.

a NIC is an Network Interface card, Each one has its own IP address. so if a computer has more than one NIC but each of them are on different LANs, my new goal is trying to send a message from one lan, to the computer with two+ NICs and that computer sends it to the specified IP on the LAN that is specified in the packet.

[example]

[NETWORK #1]

PC1 (one NIC)

PC2 (one NIC)

PC3 (two NICs)

[NETWORK #2]

PC1 (one NIC)

PC2 (one NIC)

PC3 (two NICs)

[NETWORK #3]

PC1 (one NIC)

PC2 (one NIC)

PC3 (one NIC)

NET#1 PC3 is connected both on NET#1 and NET#2

NET#2 PC3 is connected both on NET#2 and NET#3

NET#1 PC1 trys sending packet to NET#3 PC2, packet goes to NET#1 PC3 (cause it has two NICs) forwards it to NET#2 PC3 (cause it has two NICs) and then forwards it to NET#3 PC2

here is a drawn out version.

thats my dream atleast. to have every client script have a list of every single network they are capable of being connected to, and every ip on it. to have each client script act as both a User Interface on the surface, and a router running in the background. an OMNI connection.

EDIT: upon rethinking my goal, this idea could be a HUGE security risk if i were to bridge two LANs together without the user knowing. gonna have to make up another game plan.

I see.

So, do you want to bridge the NIC's in a way that all data can be routed in the fashion your proposing, or just data that your script will handle. Or in other words;

1. Do you want all programs to be able to use your script to route messages: Internet explorer, netmeeting etc.

Or...

2. Just have your 'serverless udp' script be able to route messages in each fashion. AKA: your writing a communication program, and you just want it to route messages in this fashion.

If you want option two, then you just establish connections to everyone on each NIC you can reach, then just 'hop' like stated above.

If your after option two, then I have no idea. The problem is that interfering with such a low layer of communications (NAT & IP routing) is extremely hard. The best I can think of is 'tunneling' somehow all unroutable data through your UDF to the other side, and trying to reproduce the data there. But just typing that now is confusing me.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

yeah, i was looking at #2. but opening sockets and bridging LANs is the same as punching holes into the networks security. i'm not sure how to aquire all the IPs,or even store the IPs for #2. meh, another task for another day, i've got other stuff to do.

BTW what do you think of it right now? as is the script up top?

Is there any way i could improve it or make it more dynamic, i haven't found an error on any of the machines i've tested on yet.

Link to comment
Share on other sites

Hmmmmmmmmmmmmmmm.

Your script is good.

I like your management and detection of multiple NICs, as well as dsicovery of their information.

Although im not sure its nessessary.

I was under the impression that if you called a TCPListen or UDP func to listen for messages/connections to your computer, you could just use the listening IP 0.0.0.0 and it would listen for ALL incoming data on that port for ALL nics/all IP addresses. Thats always worked for me on my many P2P Node scripts.

That way you do not have to detect all the IP's and listen to all of them.

From wat I can see, your script is a P2P node to route basic chat data across multiple Lans over a streamlined interface. (if im wrong its because I cant run your script cause Im at school and if I crash the school servers accidentally again I'll be suspended)

If I am right, then It looks like an awesome script, with a bit of simplify and some routing logic, It could be an awesome P2P network!!!

Also, you keep saying that your script opens a security risk. How is this the case? I was under the impression that any network data that is being exhanged in your system will remain within the Autoit interpreter and at worst crash your script. Surely its not a 'gateway' for hackers?

-Tom

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

Hmmmmmmmmmmmmmmm.

Your script is good.

I like your management and detection of multiple NICs, as well as dsicovery of their information.

Although im not sure its nessessary.

I was under the impression that if you called a TCPListen or UDP func to listen for messages/connections to your computer, you could just use the listening IP 0.0.0.0 and it would listen for ALL incoming data on that port for ALL nics/all IP addresses. Thats always worked for me on my many P2P Node scripts.

That way you do not have to detect all the IP's and listen to all of them.

From wat I can see, your script is a P2P node to route basic chat data across multiple Lans over a streamlined interface. (if im wrong its because I cant run your script cause Im at school and if I crash the school servers accidentally again I'll be suspended)

If I am right, then It looks like an awesome script, with a bit of simplify and some routing logic, It could be an awesome P2P network!!!

Also, you keep saying that your script opens a security risk. How is this the case? I was under the impression that any network data that is being exhanged in your system will remain within the Autoit interpreter and at worst crash your script. Surely its not a 'gateway' for hackers?

-Tom

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

it creates a socket to other computers, and my vision is to bridge LANs with these sockets, and so that would mean that the LANs aren't completely secure anymore, they have little pin prick holes in their security, where there is a will there is a way, at-least in the computer world. had someone wanted into a specific LAN there wouldn't be a way into it until my script builds a bridge. thats what i always thought. maybe you're right maybe its all under autoit control, that would be awesome!

i didn't know that 0.0.0.0 is a broadcast data recv IP. CISCO never taught me that yet. :graduated: what i had intended for using the NICs broadcasting IP and a socket for each NIC was to keep it organized and recorded. its why i don't use 255.255.255.255 as a broadcast IP. right now the NICs and their networks are separate and organized. you're right, i might have to start using the built in broadcasting IPs 0.0.0.0 and 255.255.255.255 if i want to bridge LANs. i'm still not sure how i'm going to go about doing so.

Link to comment
Share on other sites

Hmmmm.

Ive always worried about security issues; my stance is just to build the best software you can, and go from there. Also any vulnerabilities within the Winsock system are microsoft's problems. As they get fixed(if they exist); our scripts will be more secure, but thats a problem with all network layer interfaces, not just autoit!

I don't know if 0.0.0.0 is a 'broadcast recv IP' as you say; Im not a computer expert, im a 15 yo student in a foreign country. All I know is that it listens for requests from all IP's associated with that computer on that socket so in other words (probably) all NIC's. I only have,one NIC, so I cannot test to see if that is the case.

Do you work for CISCO?

-Tom

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

no i take CISCO courses in my highschool.

i know that for each 256 octet, two or so IPs that can't be used 0.0.0.0 and 255.255.255.255. and i guess a loopback IP 127.0.0.1

i just can't wrap my head around this.

to get all IPs on all possible LANs including Bridged LANs. i would need a recursive func. and for that what if there isn't an end point and another bridge is leading the path all the way back to the beginning LAN? makes an infinite recursion. once agaian. stumped. lol

Link to comment
Share on other sites

no i take CISCO courses in my highschool.

i know that for each 256 octet, two or so IPs that can't be used 0.0.0.0 and 255.255.255.255. and i guess a loopback IP 127.0.0.1

i just can't wrap my head around this.

to get all IPs on all possible LANs including Bridged LANs. i would need a recursive func. and for that what if there isn't an end point and another bridge is leading the path all the way back to the beginning LAN? makes an infinite recursion. once agaian. stumped. lol

Once again, I think your overcomplicating things. Lets start from the beginning. Correct me if Im wrong.

Your trying to make a script that can connect to the same script running on different LANS. aka. A P2P node that can communicate on mulitple NICS.

You ALREADY achieved that in the post you made at the beginning; your original script can do that just fine. (I think)

Thus, all that would be left to do would be to put some routing logic in for your message delievery system hm?

I don't know why you would want to discover all the IP's in the LAN. If your trying to find a way to bootstrap, just use the google service engine.

If your trying to stop an infinite recursive function, what about having an array holding all IP's that have been processed on each LAN (so multi demensional) and everytime it finds a new one it checks to see if you have already seen it and if so, stop? to make sure that it doesn't loop forever.

I have that for my message routing system. Every message is assigned a random number, and if the node can match the number into an array, then it knows it's seen it before, so it can drop it rather than broadcast it. That stop the 'hop' messages looping forever.

Hmmm. Start simple. Lets get the nodes talkin to each other. Why are you using UDP btw? Why not TCP? It works better and it garantees message delievery.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

i used UDP because i didn't want to waste resources by having a socket for each connection on each computer, 3 computers on a network would have 4 connections each. so in total the network would be using 12 connections all at the same time. a network with 50 computers in it would have 51 connections each (50*51 total). lots.

UDP doesn't need a constant connection. so i chose it for that reason.

and because IPs can be reused in a private network i'll probably use the NICs GUID (or MAC address if thats more familiar to you) as every NIC has a unique one.

why do i want to have an omni-connection script? yeah primarily for a communications program, maybe FTP, depending what you want, so much can be done using a network. for example: you want to talk to somebody Via IM, but they don't have Live, or G-Talk, or Facebook, BUT they are on the same network as you, or perhaps a bridged network, with this idea you could contact them even if they are on a private network not connected to the internet.

you're right recursion would still work, even if i didn't use IPs i could use the GUID (MAC Address) and organize it like this, for both the local PC and every Node on the network:

@ComputerName

---{GUID1}

---|---Local IP

---|---Networked Computers

---|---|---@ComputerName

ect...

---{GUID2}

ect...

-- on second thought. i'm wondering if maybe there could be a Request to Join Network for a computer with multiple nics, if yes then bridge the two. hmm.... lots of ideas, now to implement them.

-- sorry haha kind thinking outloud.

Link to comment
Share on other sites

i used UDP because i didn't want to waste resources by having a socket for each connection on each computer, 3 computers on a network would have 4 connections each. so in total the network would be using 12 connections all at the same time. a network with 50 computers in it would have 51 connections each (50*51 total). lots.

UDP doesn't need a constant connection. so i chose it for that reason.

and because IPs can be reused in a private network i'll probably use the NICs GUID (or MAC address if thats more familiar to you) as every NIC has a unique one.

why do i want to have an omni-connection script? yeah primarily for a communications program, maybe FTP, depending what you want, so much can be done using a network. for example: you want to talk to somebody Via IM, but they don't have Live, or G-Talk, or Facebook, BUT they are on the same network as you, or perhaps a bridged network, with this idea you could contact them even if they are on a private network not connected to the internet.

you're right recursion would still work, even if i didn't use IPs i could use the GUID (MAC Address) and organize it like this, for both the local PC and every Node on the network:

@ComputerName

---{GUID1}

---|---Local IP

---|---Networked Computers

---|---|---@ComputerName

ect...

---{GUID2}

ect...

-- on second thought. i'm wondering if maybe there could be a Request to Join Network for a computer with multiple nics, if yes then bridge the two. hmm.... lots of ideas, now to implement them.

-- sorry haha kind thinking outloud.

I have a chat program designed to work over a lan network and subnets of an entire network (over however many network NIC's and whatnot there are), and also if there is a server on the outside, exchange data with other schools (Its a school chat program Im making) over the internet. I think It will work for your purpose. The trick to have a unique identifier for each node. You could use the MAC address as you suggest, but I use a random number between 99-999999999 instead. Now that my school exams are over Im going to push out the first release. Ill give it to you one monday (72 hours). Its just one way you could structure your network.

Also having 51 connections is not a bad thing. In a P2P small world network you could get by with 4 connections per computer but thats inefficient. 35 Sockets per computer is a good number and I have that as my max (with my automatic connection number at 12)

The Problem with UDP is that there is no garantee that your message is getting through, and it really f***s up when It comes to dealing with firewalls. With TCP at least if you can start a connection you can hold a connection (as the router adds it's signature to give the message a route to get back) where as with UDP that doesn't really happen. But the biggest problem by far is that delievery of your messages is not garanteed, so your gonna have to figure out a way to count and resend failed packets.

So thats why TCP is like, the big abusive husband to UDP.

It doesn't really take up much resources. Or at least on any of my test systems... =]

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

hmmm... interesting.

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...