ipmitool 发表于 2017-1-6 17:31:32

[已解决]有人有辦法擷取putty的文字 並且抓出想要的字串嗎?

本帖最后由 ipmitool 于 2017-1-9 13:41 编辑

有人有辦法擷取putty的文字 並且抓出想要的字串嗎?
putty的視窗會一直跑字出來, 所以要偵測這個視窗, 然後抓出192.8.1.175:1 變成一個變數

q410225 发表于 2017-1-6 19:39:01

开启putty的日志功能,然后用正则提取IP

austere 发表于 2017-1-6 20:59:17

楼上思路不错~

ipmitool 发表于 2017-1-8 21:12:13

回复 2# q410225


    不過要如何指定那個位置而找到ip呢?

austere 发表于 2017-1-8 22:47:50

回复 4# ipmitool


    Afan有个匹配ip的正则,要不你就百度一下匹配IP的正则

ipmitool 发表于 2017-1-9 08:55:59

回复 5# austere

他那篇回覆的看不太明白...
如果要正則抓取這個檔案裏面的 192.8.1.175:1 要如何做啊...

zghwelcome 发表于 2017-1-9 09:39:47

(\d{1,3}\.){3}\d{1,3}(:\d+)?不是很严谨

ipmitool 发表于 2017-1-9 09:57:20

回复 7# zghwelcome


    好像沒辦法耶...一直跑出1#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#include<array.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>



    $Form1 = GUICreate("Collect FIO Log Tool", 520, 230, -1, -1)
        $Radio1        = GUICtrlCreateRadio("Collect 1HDD", 400, 50, 97, 25)
        $Button1 = GUICtrlCreateButton("Collect Log", 400, 150, 97, 25, 0)
        $hLabel1 = GUICtrlCreateLabel("BW", 30, 14, 97, 25, 0)


    GUISetState(@SW_SHOW)



    Local $var = FileOpenDialog("請選擇要開啟的檔案", "c:\data", " TXT(*.*) ")
    Local $file = FileOpen($var)

    $Input1 = GUICtrlCreateEdit("", 30, 30, 100, 175)


While 1
    ;read printer information
    $line = FileRead($file)
    $prn000 = StringRegExp($line, "(\d{1,3}\.){3}\d{1,3}(:\d+)?", 3)


GUICtrlSetData ($Input1, $prn000 &@CRLF,1)



        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                if BitAnd(GUICtrlRead($Radio1),$GUI_CHECKED)=1 Then
                        RunWait(@DesktopDir&"\dopdf-7.exe","")
                EndIf
EndSwitch



WEnd

zghwelcome 发表于 2017-1-9 10:00:24

$prn000 = StringRegExp($line, "(\d{1,3}\.){3}\d{1,3}(:\d+)?", 4)
先看下结果,然后取对应的

zghwelcome 发表于 2017-1-9 10:02:33

正则返回的是数组

zghwelcome 发表于 2017-1-9 10:14:46

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#include <array.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>



$Form1 = GUICreate("Collect FIO Log Tool", 520, 230, -1, -1)
$Radio1 = GUICtrlCreateRadio("Collect 1HDD", 400, 50, 97, 25)
$Button1 = GUICtrlCreateButton("Collect Log", 400, 150, 97, 25, 0)
$hLabel1 = GUICtrlCreateLabel("BW", 30, 14, 97, 25, 0)

GUISetState(@SW_SHOW)

Local $var = FileOpenDialog("請選擇要開啟的檔案", "c:\data", " TXT(*.*) ")

$Input1 = GUICtrlCreateEdit("", 30, 30, 100, 175)

While 1
        ;read printer information
        $line = FileRead($var)
        $prn000 = StringRegExp($line, "(\d{1,3}\.){3}\d{1,3}(:\d+)?", 4)
        If Not @error Then
                For $i = 0 To UBound($prn000) - 1
                        GUICtrlSetData($Input1, ($prn000[$i]) & @CRLF, 1)
                Next
                Sleep(5000)
        EndIf


        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) = 1 Then
                                RunWait(@DesktopDir & "\dopdf-7.exe", "")
                        EndIf
        EndSwitch

WEnd

ipmitool 发表于 2017-1-9 10:36:57

回复 11# zghwelcome


謝謝您, 不過去讀zip裡面的 txt 檔案時, 抓不到 192.8.1.175:1

zghwelcome 发表于 2017-1-9 11:29:32

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#include <array.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>



$Form1 = GUICreate("Collect FIO Log Tool", 520, 230, -1, -1)
$Radio1 = GUICtrlCreateRadio("Collect 1HDD", 400, 50, 97, 25)
$Button1 = GUICtrlCreateButton("Collect Log", 400, 150, 97, 25, 0)
$hLabel1 = GUICtrlCreateLabel("BW", 30, 14, 97, 25, 0)

GUISetState(@SW_SHOW)

Local $file = FileOpenDialog("請選擇要開啟的檔案", "c:\data", " TXT(*.*) ")

$Input1 = GUICtrlCreateEdit("", 30, 30, 100, 175)

While 1
      ;read printer information
      $sRead = BinaryToString(FileRead($file),4)
      $prn000 = StringRegExp($sRead, "(\d{1,3}\.){3}\d{1,3}(:\d+)?", 4)
      If Not @error Then
                For $i = 0 To UBound($prn000) - 1
                        GUICtrlSetData($Input1, ($prn000[$i]) & @CRLF, 1)
                Next
                Sleep(5000)
      EndIf


      $Msg = GUIGetMsg()
      Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) = 1 Then
                              RunWait(@DesktopDir & "\dopdf-7.exe", "")
                        EndIf
      EndSwitch

WEnd

ipmitool 发表于 2017-1-9 13:41:32

回复 13# zghwelcome


    好強啊~~謝謝大哥~~
页: [1]
查看完整版本: [已解决]有人有辦法擷取putty的文字 並且抓出想要的字串嗎?