bang1902 Posted August 13, 2012 Share Posted August 13, 2012 Hi all,I use function Ping, I have a problem:Ping IP add: 192.168.1.1 -> result: goodPing IP add: 192.168.001.001 -> result: not reach able.I ping 192.168.001.001 because I use Function FileRead ( "filehandle/filename" [, count] ) to get IP add in the text file with count = 15Help me.Thanks! Link to comment Share on other sites More sharing options...
iamtheky Posted August 13, 2012 Share Posted August 13, 2012 (edited) this would remove leading zeroes from an IP address $str = "192.168.001.001" $strArray = stringsplit($str , "." , 2) for $i = 0 to ubound($strArray) - 1 If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) Endif next $str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3] msgbox (0, '' , $str) Edited August 13, 2012 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
UEZ Posted August 13, 2012 Share Posted August 13, 2012 (edited) Here another method: $sIP = "192.168.001.001" MsgBox(0, "Test", ReformatIP($sIP)) Func ReformatIP($sIP) Local $aTmp = StringSplit($sIP, ".", 2) Return StringFormat("%-0d.%-0d.%-0d.%-0d", $aTmp[0], $aTmp[1], $aTmp[2], $aTmp[3]) EndFunc Why did you post it here (ActiveX/COM Help and Support (AutoItX))? Br, UEZ Edited August 13, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
bang1902 Posted August 14, 2012 Author Share Posted August 14, 2012 this would remove leading zeroes from an IP address $str = "192.168.001.001" $strArray = stringsplit($str , "." , 2) for $i = 0 to ubound($strArray) - 1 If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) Endif next $str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3] msgbox (0, '' , $str) Thanks, I think that you right. Link to comment Share on other sites More sharing options...
bang1902 Posted August 14, 2012 Author Share Posted August 14, 2012 Here another method: $sIP = "192.168.001.001" MsgBox(0, "Test", ReformatIP($sIP)) Func ReformatIP($sIP) Local $aTmp = StringSplit($sIP, ".", 2) Return StringFormat("%-0d.%-0d.%-0d.%-0d", $aTmp[0], $aTmp[1], $aTmp[2], $aTmp[3]) EndFunc Why did you post it here (ActiveX/COM Help and Support (AutoItX))? Br, UEZ Thanks. I will post it later. Link to comment Share on other sites More sharing options...
bang1902 Posted August 15, 2012 Author Share Posted August 15, 2012 (edited) #include <File.au3> global $line = _FileCountLines("ipadd.txt") ;MsgBox (0, "so dong:", $line) for $j = 1 to 5 +1 for $k = 1 to $line +1 $str = FileReadLine ("ipadd.txt",$k) If @error = -1 Then ExitLoop $strArray = stringsplit($str , "." , 2) for $i = 0 to ubound($strArray) - 1 If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1) Endif next $str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3] ;msgbox (0, '' , $strArray[4]) Local $var = Ping($str,2500) If $var Then; also possible: If @error = 0 Then ... ;MsgBox(0, "Status", "Online, roundtrip was:" & $var) Else $time = @hour & ":" & @MIN &"---"& @MDAY &"/"& @MON &"/"& @YEAR local $file $file = FileOpen ("results.txt", 1) $data = & "Unreachable to: " $str & "--NE--" & $strArray[4] & " at: " & $time & @CRLF FileWrite ($file, $data) FileClose($file) Beep (3000) MsgBox(0, "Status", "Unreachable to: " & $str & "--NE--" & $strArray[4] &"---Error: " & @error, 5) EndIf Sleep(2000) Next Sleep (3000) Next This is my code ($strArray[4] added to explain for ip add, this is name of host). Now, I writing GUI for it. And I meet a problem about function button. I'll read more. If I need to help, I question continue. Edited August 15, 2012 by bang1902 Link to comment Share on other sites More sharing options...
bang1902 Posted August 26, 2012 Author Share Posted August 26, 2012 Hi all, I has a different method:$strArray[$i] = Number($strArray[$i]) Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2012 Share Posted August 26, 2012 I'm still having a bit of trouble relating this thread to Autoitx. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
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