Sign in to follow this  
Followers 0
AoRaToS

Lan Chatting (Help Needed)

12 posts in this topic

#1 ·  Posted (edited)

Hello everyone, I need some help, I want to make a program so that I can talk on a LAN network, I find it easy to send messages from one to another but I want something better, I want my program to find the pc's on the LAN something like the cmd net view command and then send a udp message to the ones found except from my own pc, something like online? if that pc is running the same program that I will be using it will answer to that message and appear in a list of online buddies which you can talk with by double clicking on their name...on program exit send a offline message to all so that it goes from the list...I just need some help with it all, I believe I can make it but I don't know how to list lan pc's (not with cmd net view),I believe I can make most of the rest...A nice tree view like in _GUICtrlTreeView_SetIndent.au3 would be really great!anyone interested to help?

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites



OK, I worked on it for a bit and I made a bit of the GUI as I want it,really simple....Now I need some help!

I've put it to list the net view results but I want it to separate the pc's that have LAN Talk running, I'll have to do that the way I said before,I want double clicking on a pc name (with the program running there) to open a chat window, a simple one

Also there is a problem when closing the app...It runs twice cause it's called twice, how can I fix that?

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>

Global $LANTree, $Online
Global $s_Comments[1], $n_IP[1]
Global $s_Servernames = MainGUI()

MainGUI()

Func MainGUI()

GUICreate("LAN Talk", 204, 404)

$LANTree = GUICtrlCreateTreeView(2, 2, 200, 400, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$NETVIEW = GUICtrlCreateTreeViewItem("Local Network", $LANTree)
GUICtrlSetColor(-1, 0x0000C0)
For $i = 0 To UBound($s_Servernames) - 1
    GUICtrlCreateTreeViewItem($s_Servernames[$i], $NETVIEW)
Next
GUICtrlSetState($NETVIEW, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUISetState()
TCPStartup()
Local $s_Buf = ''
Local $a_Buf = ''
Local $i_Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 2 + 4)
While Not @error
    $s_Buf &= StdoutRead($i_Pid)
WEnd
Local $netView_Lines = StringSplit($s_Buf, @LF)
ReDim $s_Comments[UBound($netView_Lines) ]
ReDim $n_IP[UBound($netView_Lines) ]
$a_Buf = StringRegExp($s_Buf, "\\\\([0-9a-zA-Z-]*)", 3)
ProcessClose($i_Pid)
Return $a_Buf
; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

While 1
    Sleep(100)
WEnd

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

Also there is a problem when closing the app...It runs twice cause it's called twice, how can I fix that?

put this at the top of your script, change "my script" to something else..

$g_szV="my script"
If WinExists($g_szV) Then Exit
AutoItWinSetTitle($g_szV)

people are anoying, am i? ;) v2.95

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What is "net view" showing for you? Because all I get on mine is:

C:\>net view
Server Name         Remark

---------------------------------------------
\\UNICRON             The Devourer of Worlds
The command completed successfully.

There are 4 computers on the network though, that's just mine.

Edited by RobSaunders

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

C:\Documents and Settings\$$$$$$$$$>net view
Server Name         Remark

---------------------------------------------------
\\AORATOS
\\PINKY
\\ROBOT
The command completed successfully.

It's shows the 3 pc's on my network that are turned on at the moment (AORATOS is mine)

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

The computers are up and running whenever you try right?

I changed the code a bit and I found what I'd forgot, now it closes properly and only starts once...

I split the main function into two different functions so it doesn't run twice and added the (I always forget it at the beginning) GUIOnEventMode.

Here is the new code, I'll post my next moves soon, I'll get to it as I'm inspired at the moment...

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode",1)

Global $LANTree, $Online, $NETVIEW
Global $s_Comments[1], $n_IP[1]
Global $s_Servernames = NetView()

MainGUI()

Func NetView()
    TCPStartup()
    Local $s_Buf = ''
    Local $a_Buf = ''
    Local $i_Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 2 + 4)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    Local $netView_Lines = StringSplit($s_Buf, @LF)
    ReDim $s_Comments[UBound($netView_Lines) ]
    ReDim $n_IP[UBound($netView_Lines) ]
    $a_Buf = StringRegExp($s_Buf, "\\\\([0-9a-zA-Z-]*)", 3)
    ProcessClose($i_Pid)
    Return $a_Buf
EndFunc

Func MainGUI()

GUICreate("LAN Talk", 204, 404)
$LANTree = GUICtrlCreateTreeView(2, 2, 200, 400, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$NETVIEW = GUICtrlCreateTreeViewItem("Local Network", $LANTree)
GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")
GUICtrlSetColor(-1, 0x0000C0)
For $i = 0 To UBound($s_Servernames) - 1
    GUICtrlCreateTreeViewItem($s_Servernames[$i], $NETVIEW)
Next
GUICtrlSetState($NETVIEW, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUISetState()
EndFunc

Func OnExit()
    GUIDelete()
    Exit
EndFunc

While 1
    Sleep(100)
WEnd

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

Ok I think it's a bit better now, closer to what I want but I want some help...Can someone help with the code so that when someone already is in the list he won't appear in it asecond time?like 2 instances of the same user...I also need it to erase the user from the treeview when he closes the app and I want it to send a packet and notify it's onlin (the client count)...

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>

Opt("GUIOnEventMode",1)
Opt("TrayMenuMode",1)
TraySetIcon("Shell32.dll",16)

Global $LANTree, $Online, $NETVIEW
;Global $s_Comments[1], $n_IP[1]
;Global $s_Servernames = NetView()
Global $PrivateIP = @IPAddress1
Global $serversocket = 0
Global $clientname, $contactcast, $changeaddress, $contactdata

TCPStartup()

MainGUI()
Contacts()
;Messenger()

#CS Func NetView()
    TCPStartup()
    Local $s_Buf = ''
    Local $a_Buf = ''
    Local $i_Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 2 + 4)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    Local $netView_Lines = StringSplit($s_Buf, @LF)
    ReDim $s_Comments[UBound($netView_Lines) ]
    ReDim $n_IP[UBound($netView_Lines) ]
    $a_Buf = StringRegExp($s_Buf, "\\\\([0-9a-zA-Z-]*)", 3)
    ProcessClose($i_Pid)
    Return $a_Buf
   EndFunc
#CE

Func Messenger()
    UDPStartup()
    $chatserver = UDPBind($PrivateIP, 65333)
    TrayTip("", "LAN Talk: " & @ComputerName & "(" & $PrivateIP & ")", 5)
    Sleep(3000)
    If @error <> 0 Then
        TrayTip("", @error, 10)
        Call ("OnExit")
    Else
        While 1
            $data = UDPRecv($chatserver, 5000)
            If $data <> "" Then
                MsgBox(0,"a",$data)
            EndIf
            sleep(100)
        WEnd
    EndIf
EndFunc

Func Contacts()
;start contact server
    UDPStartup()
    $contactserver = UDPBind($PrivateIP, 65335)
    TrayTip("", "LAN Talk: " & @ComputerName & "(" & $PrivateIP & ")", 5)
    Sleep(2000)
;create multicast address
    $splitaddress = StringSplit($PrivateIP, ".")
    $changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"
    MsgBox(0,"Multicast address",$changeaddress)
;send packet
    $contactcast = UDPOpen($changeaddress, 65335)
    UDPSend($contactcast, "LT-ONLINE?" & $PrivateIP & "|" & @ComputerName)
    UDPCloseSocket($contactcast)
    While 1
        $contactdata = UDPRecv($contactserver, 50)
        If $contactdata <> "" Then
            If StringLeft($contactdata,10) = "LT-ONLINE?" Then
                $clientipname = StringMid($contactdata, 11)
                $client = StringSplit($clientipname, "|")
                $clientip = $client[1]
                $clientname = $client[2]
                If $clientip <> $PrivateIP Then
                    If StringInStr($NETVIEW, $clientip, 2) = 0 Then
                        $clientitem = GUICtrlCreateTreeViewItem($clientname & " - " & $clientip, $NETVIEW)
                        GUICtrlSetState($NETVIEW, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
                    EndIf
                EndIf
            ElseIf StringLeft($contactdata,8) = "SIGN-OFF" Then
                $clientipname = StringMid($contactdata, 11)
                $client = StringSplit($clientipname, "|")
                $clientip = $client[1]
                $clientname = $client[2]
                If $clientip <> $PrivateIP Then
                    _GUICtrlTreeView_Delete($clientitem)
                    GUICtrlSetState($NETVIEW, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
                EndIf
            EndIf
        EndIf
    WEnd
EndFunc
            
Func Countclients()
    $multisocket = UDPOpen($changeaddress, 65333)
    UDPSend($multisocket, "LT-ONLINE?" & $PrivateIP & "|" & @ComputerName)
    UDPCloseSocket($multisocket)
EndFunc

Func MainGUI()
    GUICreate("LAN Talk", 204, 404)
    $LANTree = GUICtrlCreateTreeView(2, 2, 200, 400, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $NETVIEW = GUICtrlCreateTreeViewItem("Local Network", $LANTree)
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")
    GUICtrlSetColor(-1, 0x0000C0)
    GUICtrlSetState($NETVIEW, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
    GUISetState()
EndFunc

Func OnExit()
    $sign_off = UDPOpen($changeaddress, 65335)
    UDPSend($sign_off, "SIGN-OFF" & $PrivateIP & "|" & @ComputerName)
    UDPCloseSocket($sign_off)
    GUIDelete($LANTree)
    Exit
EndFunc

While 1
    Sleep(10000)
    Call("Countclients")
WEnd

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

Weird.. I wonder why mine didn't work properly...

Could it be that they belongs to different domain or workgroups? net view will only show you those belonging to the same as yourself (I believe).

Share this post


Link to post
Share on other sites

I changed the structure of the program and solved a few of the problems I had, now what I need is how to set an event to be triggered for any existing treeview

child?I want: double click a child,run a function...


s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites

Could it be that they belongs to different domain or workgroups? net view will only show you those belonging to the same as yourself (I believe).

Ah yes, I believe that was it exactly. Not to get off topic, but any ideas how I'd go about finding them anyway?

Share this post


Link to post
Share on other sites

pingsweep?

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
Sign in to follow this  
Followers 0