|
;服务端 说明目的向所有同网段的机器发送一个服务器ip信息
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
If WinExists("电脑使用记录系统服务端") Then exit
$Form1 = GUICreate("电脑使用记录系统服务端", 623, 442, 192, 124)
GUISetState(@SW_SHOW)
Global $c_ip, $s_ip, $c_port=65431, $s_port=65432, $socket = -1, $szData,$m,$listen_socket
$c_ip=@IPAddress1
TCPStartup ( )
$szData = "s_IP|" & $c_ip&"|"& $c_port
For $m =0 to 254
$s_ip = stringleft($c_ip, stringinstr($c_ip, '.', 0, 3)) & $m
$listen_socket = TCPConnect($s_ip,65432)
If $listen_socket =-1 then TCPCloseSocket($listen_socket)
If $listen_socket <> -1 Then TCPSend($listen_socket , StringToBinary($szData, 4))
Next
TCPCloseSocket($listen_socket )
TCPShutdown ( )
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
;客户端
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("电脑使用记录系统——客户端", 623, 442, 192, 124)
GUISetState(@SW_SHOW)
Global $c_ip = @IPAddress1, $s_ip, $c_port, $s_port, $Data, $listen_mark = 1,$listen_socket,$ConnectedSocket
TCPStartup()
$listen_socket = TCPListen($c_ip, 65432)
While 1
$ConnectedSocket = TCPAccept($listen_socket)
If $listen_mark = 1 and $ConnectedSocket >= 0 Then
TCPAccept($listen_socket)
$recv = TCPRecv($ConnectedSocket, 512)
$recv = BinaryToString($recv, 4)
$Data = StringSplit($recv, "|")
If $Data[1] = "s_IP" Then
$s_ip = String($Data[2])
$s_port=String($Data[3])
MsgBox(1,"",$Data[2]&"|"&$Data[3])
$listen_mark = 0
EndIf
EndIf
TCPCloseSocket($listen_socket)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
TCPCloseSocket($listen_socket )
TCPShutdown ( )
Exit
EndSwitch
WEnd |
|