Что нового

[Данные, строки] Нужно изменить в скрипте указание конкретного ип на список ип из файла

Smasy

Новичок
Сообщения
1
Репутация
0
Привет. Подскажите как в данном скрипте изменить подключение к конкретному хосту, на подключение к нескольким из списка в файле?
А точнее подключиться к первому, затеем закрыть подключение и подключится к следующему из списка?
Сам скрипт.
Код:
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


$host = "192.168.0.100" ;<<<<<<< enter here the host name or ip address
;Remote Desktop ActiveX Control Interfaces -> http://msdn.microsoft_com/en-us/library/aa383022(v=VS.85).aspx
$hGUI = GUICreate("RDP Embedded Sessions", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2") ;http://msdn.microsoft_com/en-us/library/aa381344(v=VS.85).aspx
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ;<<<<<<< enter here the user name
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = ""
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()

GUISetState(@SW_SHOW, $hGUI)
;~ ConsoleWrite($oRDP.GetErrorDescription() & @CRLF)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $oRDP.Disconnect()
            Exit
    EndSwitch
WEnd
 

sergioz

Знающий
Сообщения
39
Репутация
5
Код:
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global const $filename="1.txt"
Opt('GUIOnEventMode',1)
OnAutoItExitRegister("_OnAutoItExit")

global $file=FileOpen($filename)
global $hGUI = GUICreate("RDP Embedded Sessions", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUISetState(@SW_SHOW, $hGUI)
GUISetOnEvent($GUI_EVENT_CLOSE,'_Exit')
_Exit()
While 1
WEnd


Func _Exit()
	GUISetState(@SW_HIDE, $hGUI)
	$host = FileReadLine($file)
	If @error=-1 or @error=1 then Exit
	WinSetTitle($hGUI,"",$host)
	Local $oRDP = ObjCreate("MsTscAx.MsTscAx.2") ;http://msdn.microsoft_com/en-us/library/aa381344(v=VS.85).aspx
	Local $oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
	GUICtrlSetResizing(-1, $GUI_DOCKALL)
	
	if $oRDP.StartConnected Then
		$oRDP.Disconnect()
		$oRDP.StartConnected=False
	EndIf
	if StringRegExp($host,"\d{1,3}.\d{1,3}.\d{1,3}") Then
sleep(1000)
		$oRDP.DesktopWidth = 800
		$oRDP.DesktopHeight = 600
		$oRDP.Fullscreen = False
		$oRDP.ColorDepth = 16
		$oRDP.AdvancedSettings3.SmartSizing = True
		$oRDP.UserName = "" ;<<<<<<< enter here the user name
		$oRDP.Domain = ""
		$oRDP.AdvancedSettings2.ClearTextPassword = ""
		$oRDP.ConnectingText = "Connecting to " & $host
		$oRDP.DisconnectedText = "Disconnected from " & $host
		$oRDP.Server = $host
		$oRDP.StartConnected = True
		$oRDP.Connect()
sleep(1000)
	EndIf
	GUICtrlSetState($oRDP_Ctrl,16)
	GUISetState(@SW_SHOW, $hGUI)
EndFunc
Func _OnAutoItExit()
	FileClose($filename)
EndFunc


правда на некоторые адреса не коннектится (берет старые)


Добавлено:
Сообщение автоматически объединено:

я использую такое
Код:
#include 'Array.au3'
#include <GuiListView.au3>

Opt('GUIOnEventMode', 1)

_init()

AdlibRegister("_ping_srv", 300000)
_ping_srv()

Global $timer = TimerInit()

Do

Until 0


;===============================================================================
; Description:	Инициализация программы
;===============================================================================
Func _init()
	Global Const $Green = 0x00ff00
	Global Const $Yellow = 0xffff00
	Global Const $Red = 0xff0000

	Global Const $ES_AUTOVSCROLL = 64
	Global Const $ES_READONLY = 2048
	Global Const $WS_VSCROLL = 0x00200000
	Global Const $WS_EX_STATICEDGE = 0x00020000
	Global Const $GUI_DOCKRIGHT = 0x0004
	Global Const $GUI_EVENT_CLOSE = -3

;~ размеры рабочей части окна
	Const $lw_name_width = 110
	Const $lw_ip_width = 100
	Const $lw_width = 5 + $lw_name_width + $lw_ip_width
	Const $edit_width = 200
	Const $global_width = $lw_width + $edit_width + 15
	Const $global_height = 950

	Global $Form1 = GUICreate("Тест соединения", $global_width, $global_height, -1, -1)

	Global $listview = GUICtrlCreateListView("имя|ip", 5, 5, $lw_width, $global_height - 10)
	_GUICtrlListView_RegisterSortCallBack($listview);сортировка столбцов
	_GUICtrlListView_SetColumnWidth($listview, 0, $lw_name_width)
	_GUICtrlListView_SetColumnWidth($listview, 1, $lw_ip_width)

;~ читаем список оборудования
	Global $serverslist = IniReadSection('test_Servers.ini', 'servers')
	_ArrayDelete($serverslist, 0) ; удаляем строку с размерностью массива
	ReDim $serverslist[UBound($serverslist)][3]

	Local $i
	For $i = 0 To UBound($serverslist) - 1
		$serverslist[$i][2] = GUICtrlCreateListViewItem($serverslist[$i][0] & "|" & $serverslist[$i][1], $listview)
	Next
;~ окно вывода статистики
	Global $Edit1 = GUICtrlCreateEdit("", $lw_width + 10, 5, $edit_width, $global_height - 10, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL, $WS_EX_STATICEDGE)
	GUICtrlSetData($Edit1, @YEAR & '.' & @MON & '.' & @MDAY & ' ' & @HOUR & ':' & @MIN & ' ' & '> начало работы')
;~ GUICtrlSetResizing($Edit1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)

;~ котекстное меню
	Global $contextmenu = GUICtrlCreateContextMenu($listview)
	GUICtrlSetOnEvent($listview, '_sort_listview')

	Global $remoteconnect_term = GUICtrlCreateMenuItem("Подключить MSTSC", $contextmenu)
	GUICtrlSetOnEvent($remoteconnect_term, '_remote_connect_term')

	GUICtrlCreateMenuItem("", $contextmenu) ; create a separator line
	Global $Call_Contacts = GUICtrlCreateMenuItem("Контактное лицо", $contextmenu)
	GUICtrlSetOnEvent($Call_Contacts, '_Call_Contacts')

	GUICtrlCreateMenuItem("", $contextmenu) ; create a separator line
	Global $ping_short = GUICtrlCreateMenuItem("Ping короткий", $contextmenu)
	GUICtrlSetOnEvent($ping_short, '_ping_vserv')
	Global $ping_long = GUICtrlCreateMenuItem("Ping длинный", $contextmenu)
	GUICtrlSetOnEvent($ping_long, '_ping_vserv_long')

	GUICtrlCreateMenuItem("", $contextmenu) ; create a separator line
	Global $tracert = GUICtrlCreateMenuItem("Tracert", $contextmenu)
	GUICtrlSetOnEvent($tracert, '_tracert')

	GUICtrlCreateMenuItem("", $contextmenu) ; create a separator line
	Global $porttestselected = GUICtrlCreateMenuItem("проверка портов: набор портов", $contextmenu)
	GUICtrlSetOnEvent($porttestselected, '_porttestselected')
	Global $porttest = GUICtrlCreateMenuItem("проверка портов: 1-1024 ~ 2 минуты", $contextmenu)
	GUICtrlSetOnEvent($porttest, '_porttest')

	Global $contextmenu2 = GUICtrlCreateContextMenu($Edit1)
	Global $remoteconnect_term = GUICtrlCreateMenuItem("Очистить", $contextmenu2)

	GUISetOnEvent($GUI_EVENT_CLOSE, '_IC_Exit')

	GUISetState(@SW_SHOW)
EndFunc   ;==>_init


;===============================================================================
; Description:	Выход
;===============================================================================
Func _IC_Exit()
	Exit
EndFunc   ;==>_IC_Exit
;===============================================================================
; Description:	Ping выбранного видеосервера
;===============================================================================
Func _ping_vserv()
	Local $temp = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')
	Run(@ComSpec & " /c " & "echo connect test " & $temp[1] & "& ping " & $temp[2] & " & pause")
	$temp = ''
EndFunc   ;==>_ping_vserv

Func _ping_vserv_long()
	Local $temp = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')
	Run(@ComSpec & " /c " & "echo connect test " & $temp[1] & " & ping -t " & $temp[2])
	$temp = ''
EndFunc   ;==>_ping_vserv_long
;===============================================================================
; Description:	Трассировка
;===============================================================================
Func _tracert()
	Local $temp = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')
	Run(@ComSpec & " /c " & "echo tracert test " & $temp[1] & "& tracert " & $temp[2] & " & pause")
	$temp = ''
EndFunc   ;==>_tracert

;===============================================================================
; Description:	подключение к терминальному серверу
;===============================================================================
Func _remote_connect_term()
	Local $temp = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')
	Run("mstsc.exe /v:" & $temp[2])
EndFunc   ;==>_remote_connect_term

;===============================================================================
; Description:	отсортировать ListView
;===============================================================================
Func _sort_listview()
	_GUICtrlListView_SortItems($listview, GUICtrlGetState($listview))
EndFunc   ;==>_sort_listview

;===============================================================================
; Description:	проверка связи пингом
;===============================================================================
Func _ping_srv()
	Local $i

	For $i = 0 To UBound($serverslist) - 1
		If Ping($serverslist[$i][1], 50) Or Ping($serverslist[$i][1], 200) Or Ping($serverslist[$i][1], 500) Or Ping($serverslist[$i][1], 2000) Then
			GUICtrlSetBkColor($serverslist[$i][2], $Green) ; зеленый - пингуется

		Else
			GUICtrlSetBkColor($serverslist[$i][2], $Yellow) ; желтый - не пингуется
			GUICtrlSetData($Edit1, @YEAR & '.' & @MON & '.' & @MDAY & ' ' & @HOUR & ':' & @MIN & ' > ' & $serverslist[$i][0] & @CRLF & GUICtrlRead($Edit1))
			TrayTip('', 'нет связи c ' & $serverslist[$i][0], 5)
;~ 			Beep(500, 150)
;~ 			Beep(400, 150)
;~ 			Beep(900, 150)
;~ 			Beep(600, 150)
;~ 			Beep(700, 150)
;~ 			Beep(800, 150)
;~ 			Beep(900, 150)
		EndIf
	Next

;~ 		Local $temp=IniRead('Servers.ini','Video_call',$vserverslist[$number][1],"")
;~ 		$temp=StringSplit($temp,',')
;~ 		if $temp[0]=4 Then	TrayTip('проблемы с сервером ' & $vserverslist[$number][1] & ' просьба связаться c:', _
;~ 																	'контактное лицо :' & @TAB & $temp[1] & @CRLF & _
;~ 																	'мобильный телефон:' & @TAB & $temp[2] & @CRLF & _
;~ 																	'IP телефон:' & @TAB & @TAB & $temp[3] & @CRLF & _
;~ 																	'городской телефон:' & @TAB & $temp[4] & @CRLF, 30, 2)

;~ 		if IniRead('Servers.ini','Video_gate',$vserverslist[$number][0],"") And not ping(IniRead('Servers.ini','Video_gate',$vserverslist[$number][0],"")) Then; сопоставляем имена с IP
;~ 			GUICtrlSetBkColor($vserverslist[$number][3],$Red) ; Красный - нет канала
;~ 		EndIf
;~ 	EndIf
;~ EndIf
EndFunc   ;==>_ping_srv

;===============================================================================
; Description:	сканер открытых портов
;===============================================================================
Func _porttest()
	Local $sIPAddress = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')[2]
	Local $i, $j=0, $ports[0][2]
	TCPStartup()
	For $i = 1 To 1024
		Local $iSocket = TCPConnect($sIPAddress, $i)
		If Not @error Then
			ReDim $ports[UBound($ports) + 1][2]
			$ports[$j][0] = $i
			$ports[$j][1] = IniRead('test_servers.ini', 'ports',$i,'')
			$j = $j + 1
		EndIf
		TCPCloseSocket($iSocket)
	Next
	TCPShutdown()
	_ArrayDisplay($ports)
EndFunc   ;==>_porttest


Func _porttestselected()
	Local $sIPAddress = StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')[2]
	local $portslist = IniReadSection('test_Servers.ini', 'portsselected')
	Local $i, $j=0, $ports[0][2]
	TCPStartup()
	For $i=1 to $portslist[0][0]
		Local $iSocket = TCPConnect($sIPAddress, $portslist[$i][0])
		If Not @error Then
			ReDim $ports[UBound($ports) + 1][2]
			$ports[$j][0] = $portslist[$i][0]
			$ports[$j][1] = $portslist[$i][1]
			$j = $j + 1
		EndIf
		TCPCloseSocket($iSocket)
	Next
	TCPShutdown()
	_ArrayDisplay($ports)
EndFunc
;===============================================================================
; Description:	контакты
;===============================================================================
Func _Call_Contacts()
	Local $look_for = StringSplit(IniRead('test_servers.ini', 'contacts', StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')[1], ""), ',')

	If $look_for[0] = 3 Then MsgBox('', 'контактные данные на ' & StringSplit(GUICtrlRead(GUICtrlRead($listview)), '|')[1], _
			'контактное лицо  :' & @TAB & @TAB & $look_for[1] & @CRLF & _
			'мобильный телефон:' & @TAB & $look_for[2] & @CRLF & _
			'городской телефон:' & @TAB & @TAB & $look_for[3] & @CRLF)
EndFunc   ;==>_Call_Contacts


test_servers.ini
Код:
[servers]
me		=127.0.0.1

[contacts]
me		=ФИО,моб тел,гор. тел
 
Верх