Тема: 2 VPN-туннеля между 2 Kerio Control
Показать сообщение отдельно
Старый 07.06.2014, 11:30   #6
 
Регистрация: 15.11.2011
Сообщений: 5

По умолчаниюRe: 2 VPN-туннеля между 2 Kerio Control

Вот код:
Код:
#include 
#include 
while 1
   FileDelete("C:\Windows\System32\drivers\etc\hosts.txt")
   $ping=Ping("ххх.ххх.ххх.ххх")
   If $ping Then
          Sleep(10000)
   Else
          RunWait('"' & @ComSpec & '" /c ' & 'rename C:\Windows\System32\drivers\etc\hosts hosts.txt', @WindowsDir, @SW_HIDE)
          $file=FileOpen("C:\Windows\System32\drivers\etc\hosts.txt",1)
          FileSetPos($file,0,0) 
          $CountLines=_FileCountLines("C:\Windows\System32\drivers\etc\hosts.txt")
          $z=0
          For $i = 1 to $CountLines
                 $line = FileReadLine($file)
                 $z=StringInStr($line,"vpn.cherles.com")
                 ;MsgBox(0,$i, $line)
                 If $z>0 Then
                        _FileWriteToLine ("C:\Windows\System32\drivers\etc\hosts.txt",$i,"yyy.yyy.yyy.yyy vpn.cherles.com",1)
                        ;MsgBox(0,"0", $i)
                        ExitLoop
                 ElseIf $i=$CountLines Then
                        _FileWriteToLine ("C:\Windows\System32\drivers\etc\hosts.txt",$i+1,"yyy.yyy.yyy.yyy vpn.cherles.com",1)
                        $i=$i+1
                        ;MsgBox(0,"1", $i)
                        ExitLoop
                 EndIf
          Next
          FileClose($file)
          RunWait('"' & @ComSpec & '" /c ' & 'rename C:\Windows\System32\drivers\etc\hosts.txt hosts', @SystemDir, @SW_HIDE)
          While Not(Ping("ххх.ххх.ххх.ххх"))
                 Sleep(10000)
          WEnd
          RunWait('"' & @ComSpec & '" /c ' & 'rename C:\Windows\System32\drivers\etc\hosts hosts.txt', @SystemDir, @SW_HIDE)
          $file=FileOpen("C:\Windows\System32\drivers\etc\hosts.txt",1)
          _FileWriteToLine ("C:\Windows\System32\drivers\etc\hosts.txt",$i,"ххх.ххх.ххх.ххх vpn.cherles.com",1)
          FileClose($file)
          RunWait('"' & @ComSpec & '" /c ' & 'rename C:\Windows\System32\drivers\etc\hosts.txt hosts', @SystemDir, @SW_HIDE)
   EndIf
WEnd
Пришлось чуть-чуть поплясать с переименовыванием хостса в обычный тхт, иначе автоит не хотел с ним работать, как с текстовым файлом.
Artes1408 вне форума  Ответить с цитированием