Jump to content

Serverden, Ağdaki Bilgisayarlara İşlem Yaptırmak


blue_life
 Share

Recommended Posts

@MeHMeTBeN ağındaki serverden, komut göndererek clientteki bilgisayarlarda çalışan bazı programları kapatmak istemişti. Benden rica edince basit bir şey karaladım ve sizlerlede paylaşmak istedim.

Örnek kodlardaki server programını açınca, + butonu ile client iplerini eklemeniz gerekiyor. Ipler ini dosyasında yedekleniyordu.

Serverde çalışacak örnek programın kodları;
[codebox]; ==========================================================
Global $SOCKET
Global $PORT_NUM = 65432
Global $Confil_File = StringTrimRight(@ScriptFullPath, 4) & ".ini"

TCPStartup() ; Start The TCP Services
OnAutoItExitRegister("_EXIT")

_Server_GUI() ;Server
;~ _Client() ;Client

;~ _GUI_SELECT()
Exit
; ==========================================================

Func _GUI_SELECT()
Local $Form1 = GUICreate("BlueLife Test", 161, 33, 192, 124)
Local $Button1 = GUICtrlCreateButton("Server", 0, 0, 75, 25)
Local $Button2 = GUICtrlCreateButton("Client", 75, 0, 75, 25)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
GUIDelete($Form1)
_Server_GUI()

Case $Button2
GUIDelete($Form1)
_Client()

EndSwitch
WEnd
EndFunc ;==>_GUI_SELECT

; ==========================================================

Func _Server_GUI()
Local $Client_List[1][3] = [[0, "|"]] ;ip-isim-gctrlid

Local $IRS = IniReadSection($Confil_File, "Client_List")
If @error = 0 Then
For $i = 1 To $IRS[0][0]
If StringInStr($Client_List[0][1], "|" & $IRS[$i][0] & "|") <> 0 Then ContinueLoop
If _IP_CHECK($IRS[$i][0]) = False Then ContinueLoop

$Client_List[0][1] &= $IRS[$i][0] & "|"

$Client_List[0][0] += 1
ReDim $Client_List[$Client_List[0][0] + 1][3]

$Client_List[$Client_List[0][0]][0] = $IRS[$i][0]
$Client_List[$Client_List[0][0]][1] = $IRS[$i][1]
Next
EndIf


Local $BlueTitle = "Server_Test_Blue_Life"
Local $Blue_Gui = GUICreate($BlueTitle, 400, 400, -1, -1)
GUISetBkColor(0)
;GUISetBkColor(0xFFFFFF)

Local $Blue_ListView = GUICtrlCreateListView("", 0, 0, 400, 370)
GUICtrlSetResizing(-1, 0x0066)
GUICtrlSetStyle($Blue_ListView, 0x0004, BitOR(2048, 0x00000001))

For $i = 1 To $Client_List[0][0]
$Client_List[$i][2] = GUICtrlCreateListViewItem($Client_List[$i][1] & @CRLF & $Client_List[$i][0], $Blue_ListView)
GUICtrlSetImage($Client_List[$i][2], "explorer.exe", 1)
Next

Local $SERVER_IE_BTN = GUICtrlCreateButton("Internet Exploreri Kapat", 0, 375, 175, 25)
Local $SERVER_CHROME_BTN = GUICtrlCreateButton("Google Chromeyi Kapat", 175, 375, 175, 25)

Local $CLIENT_ADD = GUICtrlCreateButton("+", 350, 375, 25, 25)
Local $CLIENT_DEL = GUICtrlCreateButton("-", 375, 375, 25, 25)

GUISetState(@SW_SHOW, $Blue_Gui)

Local $Read_ITEM
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $SERVER_IE_BTN
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
_Client_Send_Message("Pclose=iexplore.exe", $Client_List[$i][0], $PORT_NUM, $Blue_Gui)
ExitLoop
EndIf
Next

Case $SERVER_CHROME_BTN
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
_Client_Send_Message("Pclose=Chrome.exe", $Client_List[$i][0], $PORT_NUM, $Blue_Gui)
ExitLoop
EndIf
Next

Case $CLIENT_DEL
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
GUICtrlDelete($Read_ITEM)
$Client_List[$i][2] = -1
$Client_List[0][1] = StringReplace($Client_List[0][1], "|" & $Client_List[$i][0] & "|", "|")
IniDelete($Confil_File, "Client_List", $Client_List[$i][0])
ExitLoop
EndIf
Next

Case $CLIENT_ADD
$Read_ITEM = _Add_Client($Blue_Gui)
If @error <> 0 Then ContinueCase
If StringInStr($Client_List[0][1], "|" & $Read_ITEM[0] & "|") <> 0 Then ContinueCase

$Client_List[0][1] &= $Read_ITEM[0] & "|"

$Client_List[0][0] += 1
ReDim $Client_List[$Client_List[0][0] + 1][3]

$Client_List[$Client_List[0][0]][0] = $Read_ITEM[0]
$Client_List[$Client_List[0][0]][1] = $Read_ITEM[1]

$Client_List[$Client_List[0][0]][2] = GUICtrlCreateListViewItem($Client_List[$Client_List[0][0]][1] & @CRLF & $Client_List[$Client_List[0][0]][0], $Blue_ListView)
GUICtrlSetImage($Client_List[$Client_List[0][0]][2], "explorer.exe", 1)
EndSwitch
WEnd
EndFunc ;==>_Server_GUI

Func _Add_Client($hwnd = 0)
Local $Return_Array[2]
If IsHWnd($hwnd) = 1 Then GUISetState(@SW_DISABLE, $hwnd)
Local $ADD_IP_GUI = GUICreate("Bilgisayar Ekle", 400, 50, -1, -1, BitOR(0x80880000, 0x00C00000), 0x00000010, $hwnd)
GUICtrlCreateGroup("Ip Adresini Giriniz", 5, 5, 150, 40)
Local $IP_INPUT = GUICtrlCreateInput("", 10, 20, 140, 20)

GUICtrlCreateGroup("Bilgisayarın İsmini Giriniz", 160, 5, 150, 40)
Local $CN_INPUT = GUICtrlCreateInput("", 165, 20, 140, 20)

Local $ADD_IP_OK = GUICtrlCreateButton("Ekle", 315, 5, 80, 40)
GUISetState(@SW_SHOW, $ADD_IP_GUI)

Local $READ_INPUT1, $READ_INPUT2
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
ExitLoop
Case $ADD_IP_OK
$Return_Array[0] = StringStripWS(GUICtrlRead($IP_INPUT), 3)
If _IP_CHECK($Return_Array[0]) = False Then
MsgBox(64, "Hata", "İp adresi hatalı!", 0, $ADD_IP_GUI)
GUICtrlSetState($IP_INPUT, 256)
ContinueCase
EndIf

$Return_Array[1] = StringStripWS(GUICtrlRead($CN_INPUT), 3)
If $Return_Array[1] = "" Then
MsgBox(64, "Hata", "Bilgisyarın ismini giriniz.", 0, $ADD_IP_GUI)
GUICtrlSetState($CN_INPUT, 256)
ContinueCase
EndIf

IniWrite($Confil_File, "Client_List", $Return_Array[0], $Return_Array[1])
ExitLoop
EndSwitch
WEnd
If IsHWnd($hwnd) = 1 Then
GUISetState(@SW_ENABLE, $hwnd)
GUISwitch($hwnd)
EndIf
GUIDelete($ADD_IP_GUI)

If $Return_Array[1] = "" Then Return SetError(1, 0, $Return_Array)
Return $Return_Array
EndFunc ;==>_Add_Client

Func _IP_CHECK($IP_CHECK)
Local $Value = StringSplit($IP_CHECK, ".")
If $Value[0] = 4 And StringIsDigit($Value[1]) And StringIsDigit($Value[2]) And StringIsDigit($Value[3]) And StringIsDigit($Value[4]) Then
If $Value[1] >= 1 And $Value[1] <= 255 Then
If $Value[2] >= 0 And $Value[2] <= 255 Then
If $Value[3] >= 0 And $Value[3] <= 255 Then
If $Value[4] >= 0 And $Value[4] <= 255 Then
Return True
EndIf
EndIf
EndIf
EndIf
EndIf
Return False
EndFunc ;==>_IP_CHECK

; ==========================================================

Func _Client_Send_Message($Send_MSG, $IP, $Port, $hwnd = 0)
$SOCKET = TCPConnect($IP, $Port)
If @error Then
MsgBox(0, "Blue_Server", "Client ile bağlantı kurulumadı!" & @CRLF & @CRLF & "ip=:" & $IP & @CRLF & "port:" & $Port, 0, $hwnd)
Return SetError(1, 0, 0)
EndIf

Local $RECV = TCPRecv($SOCKET, 256)
If @error Then
MsgBox(0, "Blue_Server", "Client ile bağlantı kurulumadı!" & @CRLF & @CRLF & "ip=:" & $IP & @CRLF & "port:" & $Port, 0, $hwnd)
Return SetError(1, 0, 0)
EndIf
TCPSend($SOCKET, StringToBinary($Send_MSG, 4))
TCPCloseSocket($SOCKET)
EndFunc ;==>_Client_Send_Message

; ==========================================================

Func _Client()
Local $C_IP = @IPAddress1

Local $C_SOCKET = TCPListen($C_IP, $PORT_NUM, 4)
If @error Then
MsgBox(16, "Client bağlantı hatası", "ip=:" & $C_IP & @CRLF & "port:" & $PORT_NUM)
Exit
EndIf

Local $READ_MSG
While 1
$READ_MSG = TCPRecv($SOCKET, 256)
If @error Then
TCPCloseSocket($SOCKET)
$SOCKET = -1
While $SOCKET <= 0
Sleep(5)
$SOCKET = TCPAccept($C_SOCKET)
If $SOCKET > 0 Then ExitLoop
WEnd
EndIf
If $READ_MSG <> "" Then
ToolTip($READ_MSG, 0, 0, "BlueTest") ; Bu test olarak eklenmiştir.

If StringLeft($READ_MSG, 7) = "Pclose=" Then
$READ_MSG = StringStripWS(StringTrimLeft($READ_MSG, 7), 3)
While ProcessExists($READ_MSG)
ProcessClose($READ_MSG)
Sleep(50)
WEnd
EndIf
EndIf
Sleep(10)
WEnd
EndFunc ;==>_Client

Func _EXIT()
TCPCloseSocket($SOCKET)
TCPShutdown()
Exit
EndFunc ;==>_EXIT[/codebox]

Clientte çalışacak örnek programın kodları;
[codebox]; ==========================================================
Global $SOCKET
Global $PORT_NUM = 65432
Global $Confil_File = StringTrimRight(@ScriptFullPath, 4) & ".ini"

TCPStartup() ; Start The TCP Services
OnAutoItExitRegister("_EXIT")

;~ _Server_GUI() ;Server
_Client() ;Client

;~ _GUI_SELECT()
Exit
; ==========================================================

Func _GUI_SELECT()
Local $Form1 = GUICreate("BlueLife Test", 161, 33, 192, 124)
Local $Button1 = GUICtrlCreateButton("Server", 0, 0, 75, 25)
Local $Button2 = GUICtrlCreateButton("Client", 75, 0, 75, 25)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
GUIDelete($Form1)
_Server_GUI()

Case $Button2
GUIDelete($Form1)
_Client()

EndSwitch
WEnd
EndFunc ;==>_GUI_SELECT

; ==========================================================

Func _Server_GUI()
Local $Client_List[1][3] = [[0, "|"]] ;ip-isim-gctrlid

Local $IRS = IniReadSection($Confil_File, "Client_List")
If @error = 0 Then
For $i = 1 To $IRS[0][0]
If StringInStr($Client_List[0][1], "|" & $IRS[$i][0] & "|") <> 0 Then ContinueLoop
If _IP_CHECK($IRS[$i][0]) = False Then ContinueLoop

$Client_List[0][1] &= $IRS[$i][0] & "|"

$Client_List[0][0] += 1
ReDim $Client_List[$Client_List[0][0] + 1][3]

$Client_List[$Client_List[0][0]][0] = $IRS[$i][0]
$Client_List[$Client_List[0][0]][1] = $IRS[$i][1]
Next
EndIf


Local $BlueTitle = "Server_Test_Blue_Life"
Local $Blue_Gui = GUICreate($BlueTitle, 400, 400, -1, -1)
GUISetBkColor(0)
;GUISetBkColor(0xFFFFFF)

Local $Blue_ListView = GUICtrlCreateListView("", 0, 0, 400, 370)
GUICtrlSetResizing(-1, 0x0066)
GUICtrlSetStyle($Blue_ListView, 0x0004, BitOR(2048, 0x00000001))

For $i = 1 To $Client_List[0][0]
$Client_List[$i][2] = GUICtrlCreateListViewItem($Client_List[$i][1] & @CRLF & $Client_List[$i][0], $Blue_ListView)
GUICtrlSetImage($Client_List[$i][2], "explorer.exe", 1)
Next

Local $SERVER_IE_BTN = GUICtrlCreateButton("Internet Exploreri Kapat", 0, 375, 175, 25)
Local $SERVER_CHROME_BTN = GUICtrlCreateButton("Google Chromeyi Kapat", 175, 375, 175, 25)

Local $CLIENT_ADD = GUICtrlCreateButton("+", 350, 375, 25, 25)
Local $CLIENT_DEL = GUICtrlCreateButton("-", 375, 375, 25, 25)

GUISetState(@SW_SHOW, $Blue_Gui)

Local $Read_ITEM
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $SERVER_IE_BTN
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
_Client_Send_Message("Pclose=iexplore.exe", $Client_List[$i][0], $PORT_NUM, $Blue_Gui)
ExitLoop
EndIf
Next

Case $SERVER_CHROME_BTN
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
_Client_Send_Message("Pclose=Chrome.exe", $Client_List[$i][0], $PORT_NUM, $Blue_Gui)
ExitLoop
EndIf
Next

Case $CLIENT_DEL
$Read_ITEM = GUICtrlRead($Blue_ListView)
For $i = 1 To $Client_List[0][0]
If $Client_List[$i][2] = $Read_ITEM Then
GUICtrlDelete($Read_ITEM)
$Client_List[$i][2] = -1
$Client_List[0][1] = StringReplace($Client_List[0][1], "|" & $Client_List[$i][0] & "|", "|")
IniDelete($Confil_File, "Client_List", $Client_List[$i][0])
ExitLoop
EndIf
Next

Case $CLIENT_ADD
$Read_ITEM = _Add_Client($Blue_Gui)
If @error <> 0 Then ContinueCase
If StringInStr($Client_List[0][1], "|" & $Read_ITEM[0] & "|") <> 0 Then ContinueCase

$Client_List[0][1] &= $Read_ITEM[0] & "|"

$Client_List[0][0] += 1
ReDim $Client_List[$Client_List[0][0] + 1][3]

$Client_List[$Client_List[0][0]][0] = $Read_ITEM[0]
$Client_List[$Client_List[0][0]][1] = $Read_ITEM[1]

$Client_List[$Client_List[0][0]][2] = GUICtrlCreateListViewItem($Client_List[$Client_List[0][0]][1] & @CRLF & $Client_List[$Client_List[0][0]][0], $Blue_ListView)
GUICtrlSetImage($Client_List[$Client_List[0][0]][2], "explorer.exe", 1)
EndSwitch
WEnd
EndFunc ;==>_Server_GUI

Func _Add_Client($hwnd = 0)
Local $Return_Array[2]
If IsHWnd($hwnd) = 1 Then GUISetState(@SW_DISABLE, $hwnd)
Local $ADD_IP_GUI = GUICreate("Bilgisayar Ekle", 400, 50, -1, -1, BitOR(0x80880000, 0x00C00000), 0x00000010, $hwnd)
GUICtrlCreateGroup("Ip Adresini Giriniz", 5, 5, 150, 40)
Local $IP_INPUT = GUICtrlCreateInput("", 10, 20, 140, 20)

GUICtrlCreateGroup("Bilgisayarın İsmini Giriniz", 160, 5, 150, 40)
Local $CN_INPUT = GUICtrlCreateInput("", 165, 20, 140, 20)

Local $ADD_IP_OK = GUICtrlCreateButton("Ekle", 315, 5, 80, 40)
GUISetState(@SW_SHOW, $ADD_IP_GUI)

Local $READ_INPUT1, $READ_INPUT2
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
ExitLoop
Case $ADD_IP_OK
$Return_Array[0] = StringStripWS(GUICtrlRead($IP_INPUT), 3)
If _IP_CHECK($Return_Array[0]) = False Then
MsgBox(64, "Hata", "İp adresi hatalı!", 0, $ADD_IP_GUI)
GUICtrlSetState($IP_INPUT, 256)
ContinueCase
EndIf

$Return_Array[1] = StringStripWS(GUICtrlRead($CN_INPUT), 3)
If $Return_Array[1] = "" Then
MsgBox(64, "Hata", "Bilgisyarın ismini giriniz.", 0, $ADD_IP_GUI)
GUICtrlSetState($CN_INPUT, 256)
ContinueCase
EndIf

IniWrite($Confil_File, "Client_List", $Return_Array[0], $Return_Array[1])
ExitLoop
EndSwitch
WEnd
If IsHWnd($hwnd) = 1 Then
GUISetState(@SW_ENABLE, $hwnd)
GUISwitch($hwnd)
EndIf
GUIDelete($ADD_IP_GUI)

If $Return_Array[1] = "" Then Return SetError(1, 0, $Return_Array)
Return $Return_Array
EndFunc ;==>_Add_Client

Func _IP_CHECK($IP_CHECK)
Local $Value = StringSplit($IP_CHECK, ".")
If $Value[0] = 4 And StringIsDigit($Value[1]) And StringIsDigit($Value[2]) And StringIsDigit($Value[3]) And StringIsDigit($Value[4]) Then
If $Value[1] >= 1 And $Value[1] <= 255 Then
If $Value[2] >= 0 And $Value[2] <= 255 Then
If $Value[3] >= 0 And $Value[3] <= 255 Then
If $Value[4] >= 0 And $Value[4] <= 255 Then
Return True
EndIf
EndIf
EndIf
EndIf
EndIf
Return False
EndFunc ;==>_IP_CHECK

; ==========================================================

Func _Client_Send_Message($Send_MSG, $IP, $Port, $hwnd = 0)
$SOCKET = TCPConnect($IP, $Port)
If @error Then
MsgBox(0, "Blue_Server", "Client ile bağlantı kurulumadı!" & @CRLF & @CRLF & "ip=:" & $IP & @CRLF & "port:" & $Port, 0, $hwnd)
Return SetError(1, 0, 0)
EndIf

Local $RECV = TCPRecv($SOCKET, 256)
If @error Then
MsgBox(0, "Blue_Server", "Client ile bağlantı kurulumadı!" & @CRLF & @CRLF & "ip=:" & $IP & @CRLF & "port:" & $Port, 0, $hwnd)
Return SetError(1, 0, 0)
EndIf
TCPSend($SOCKET, StringToBinary($Send_MSG, 4))
TCPCloseSocket($SOCKET)
EndFunc ;==>_Client_Send_Message

; ==========================================================

Func _Client()
Local $C_IP = @IPAddress1

Local $C_SOCKET = TCPListen($C_IP, $PORT_NUM, 4)
If @error Then
MsgBox(16, "Client bağlantı hatası", "ip=:" & $C_IP & @CRLF & "port:" & $PORT_NUM)
Exit
EndIf

Local $READ_MSG
While 1
$READ_MSG = TCPRecv($SOCKET, 256)
If @error Then
TCPCloseSocket($SOCKET)
$SOCKET = -1
While $SOCKET <= 0
Sleep(5)
$SOCKET = TCPAccept($C_SOCKET)
If $SOCKET > 0 Then ExitLoop
WEnd
EndIf
If $READ_MSG <> "" Then
ToolTip($READ_MSG, 0, 0, "BlueTest") ; Bu test olarak eklenmiştir.

If StringLeft($READ_MSG, 7) = "Pclose=" Then
$READ_MSG = StringStripWS(StringTrimLeft($READ_MSG, 7), 3)
While ProcessExists($READ_MSG)
ProcessClose($READ_MSG)
Sleep(50)
WEnd
EndIf
EndIf
Sleep(10)
WEnd
EndFunc ;==>_Client

Func _EXIT()
TCPCloseSocket($SOCKET)
TCPShutdown()
Exit
EndFunc ;==>_EXIT[/codebox]
Link to comment
Share on other sites

üstad birde şurasını bu şekilde düzenledim bir sıkıntı olmaz değilmi doğru düzenlemişmiyim yani tooltip biraz bekleyip kapansın diye yoksa sürekli o mesaj orada kalıyor

If $READ_MSG <> "" Then
ToolTip($READ_MSG, 0, 0, "YASAK SİTE KAPATILIYOR..", 10) ; Bu test olarak eklenmiştir.
Sleep(2000)
ToolTip("")

Link to comment
Share on other sites

blue_life bu konuda öncülük yaptı bize bir örnek hazırladı geliştirmeside biz autoit severlere kalıyor örneğin client'i kapatma ve client bilgisayarlara mesaj gönderme gibi
teşekkürler blue_life geliştirilmesi dileğiyle

Not: MostWanted bu konuda autoit forumlarından bir örnek sunmuştu udfsiyle beraber o örneğede bakabilirsiniz bu linkden ulaşabilirsiniz
[code]http://www.tnctr.com/topic/196724-autoitle-adh-uzerinde-ithlem-yapma/[/code]

Edited by MeHMeTBeN
Link to comment
Share on other sites

  • 6 ay sonra...

client te çalışan programlar yada pc yi kapatmak otururm kapatmak vs.. karşıya hiçbirşey yüklemeden yapılıyor zaten özellikle active directory yapısında çok basit workgroupdada çalışılabilir niye bu kadar kasıyorsunuz anlamadım ?

Edited by tnc_tr
Link to comment
Share on other sites

  • 11 ay sonra...

client te çalışan programlar yada pc yi kapatmak otururm kapatmak vs.. karşıya hiçbirşey yüklemeden yapılıyor zaten özellikle active directory yapısında çok basit workgroupdada çalışılabilir niye bu kadar kasıyorsunuz anlamadım ?

 

Burası AutoIT → Örnek Çalışmalar Bölümü...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...