allSystemsGo Posted October 31, 2013 Posted October 31, 2013 (edited) So I am working on a small project that at the moment grabs a list of PCs that are connected to the network and displays their IP address. The functionality is there but I am having one small issue. I have two StringReplace functions going on. The first one fails, but the other works. I have this same snippet of code in another script of mine that works just fine. The only difference is the name of the variables. Care to take a look and help me see what I am not seeing? #include <Filev1.au3> #include <array.au3> DirCreate("c:\temp") netreport() Func netreport() Dim $report[50][3] $report[0][0] = "Computer name" $report [0][1] = "IP Address" $pcnames = "c:\temp\pcnames.txt" RunWait(@Comspec & " /c " & "net view > " & $pcnames, "" , @SW_HIDE) FileOpen($pcnames,0) $x= 1 For $i= 4 to 100 $name = FileReadLine($pcnames,$i) $name = StringTrimLeft($name,2) $ip = RunWait(@Comspec & " /c " & "ping " & $name & ' -n 1 |Find "[" > c:\temp\yip.txt', "", @SW_HIDE) $iptxt = FileOpen("c:\temp\yip.txt",0) $ip = FileRead($iptxt) ;~ MsgBox(64,"text",$ip) $ip=StringReplace($ip,"Pinging "& $name &" [", " ") ; this does not work $ip=StringReplace($ip,"] with 32 bytes of data:"," ") ; this does work ;~ MsgBox(64,"test",$ip) $report[$x][0] = $name $report[$x][1] = $ip $i = $i + 1 $x = $x + 1 Next _ArrayDisplay($report) EndFunc Edited October 31, 2013 by allSystemsGo
Moderators Melba23 Posted October 31, 2013 Moderators Posted October 31, 2013 allSystemsGo,I would imagine that the function does not find the exact string you wish to replace and so fails. Are you sure that the string is correct? Have you checked in a binary editor that it matches? Perhaps post an example file here so we can look at it. And you might be better going with StringRegExpReplace in any case. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution mikell Posted October 31, 2013 Solution Posted October 31, 2013 Something like this maybe ? $ip = "Pinging tralala [192.168.1.1] with 32 bytes of data:" $ip = StringRegExpReplace($ip,'.+\[([^]]+).+', " $1 ") msgbox(0,"", $ip)
allSystemsGo Posted November 1, 2013 Author Posted November 1, 2013 @Mikell That did the trick. Thanks for your help.
mikell Posted November 1, 2013 Posted November 1, 2013 Melba pointed to the scent, I only wrote the conclusion
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now