Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Ikari

Новый участник


Сообщения: 18
Благодарности: 0

Профиль | Отправить PM | Цитировать


Изображения
Тип файла: jpg Снимок16.JPG
(37.2 Kb, 17 просмотров)

Гхм... на set-ExecutionPolicy RemoteSigned PS ничего не отвечал.
Скрипт поправил - ноль положительной реакции.
читать дальше »
#############################################################################
#Script to ping remote and reboot modem (zyxel)
#Original name: QRS_modemReboot.ps1
#
#Parameters: not required
#Version: 0.0
#
#Author: as QRS
##############################################################################


new-eventlog -source QRS_shutdown -logname Application -ea SilentlyContinue

function Ping-Address {
PROCESS {
$ping = $false
$results = Get-WmiObject -query `
"SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
foreach ($result in $results) {
if ($results.StatusCode -eq 0) {
$ping = $true
}
}
if ($ping -eq $true) {
Write-Output $_
}
}
}


## Read output from a remote host
function GetOutput
{
## Create a buffer to receive the response
$buffer = new-object System.Byte[] 1024
$encoding = new-object System.Text.AsciiEncoding

$outputBuffer = ""
$foundMore = $false

## Read all the data available from the stream, writing it to the
## output buffer when done.
do
{
## Allow data to buffer for a bit
start-sleep -m 1000

## Read what data is available
$foundmore = $false
$stream.ReadTimeout = 1000

do
{
try
{
$read = $stream.Read($buffer, 0, 1024)

if($read -gt 0)
{
$foundmore = $true
$outputBuffer += ($encoding.GetString($buffer, 0, $read))
}
} catch { $foundMore = $false; $read = 0 }
} while($read -gt 0)
} while($foundmore)

$outputBuffer
}


function execTelnet{

[string] $output = ""
$remoteHost = '192.168.1.1'
$port = 23;
$currentInput = @"
admin
admin
8
1
1
1
"@

$commandDelay = 500

write-host "Connecting to $remoteHost on port $port"
trap { Write-Error "Could not connect to remote computer: $_"; exit }

$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)

$stream = $socket.GetStream()

$writer = new-object System.IO.StreamWriter $stream

## Receive the output that has buffered so far
$SCRIPTutput += GetOutput
foreach($line in $currentInput)
{
$writer.WriteLine($line)
$writer.Flush()
Start-Sleep -m $commandDelay
$SCRIPTutput += GetOutput
}

## Close the streams
$writer.Close()
$stream.Close()
$output
}

$ping = (('ya.ru','google.com') | Ping-Address)
if($ping -eq $null) {
$noping = (Get-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart").noPing
if($noping -eq 1){
write-eventlog -logname Application -source QRS_shutdown -eventID 03 -entrytype Information -message "Ping lost." -category 1
. execTelnet
Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 0
}else{
Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 1
write-eventlog -logname Application -source QRS_shutdown -eventID 03 -entrytype Information -message "Ping lost first time." -category 1
}
}else{
New-Item -path "HKCU:\Software\" -name "QRS" -type directory -ea 0
New-Item -path "HKCU:\Software\QRS\" -name "ADSLrestart" -type directory -ea 0
Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 0
write-host Ping is ok!
}

-------
Нужный человек в нужном месте может изменить мир (hl2)


Отправлено: 21:58, 07-06-2010 | #9