Moderators SmOke_N Posted January 23, 2007 Moderators Share Posted January 23, 2007 (edited) I got a headache doing the RegExp on this one, it seems so simple looking at it now, but to be honest, I'm not 100% sure on the validity of it, I just know it passed all my own personal tests. Should work on 0-255. Vaildate just the string type as an IP:Func _StringIPTypeValid($sIP) If StringRegExp($sIP, "(?:(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.)){3}(?:(25[0-5]$|2[0-4]\d$|1\d{2}$|[1-9]\d$|\d$))") Then Return 1 Return SetError(1, 0, 0) EndFuncoÝ÷ Ú)Üç^اzÖ®Þgyç^uV¥ÖzØ^²Úâr¥ê+ën®{azêå Edit: Just realized I put Ping in the title description, obviously that's not being used... Edited January 23, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ptrex Posted January 23, 2007 Share Posted January 23, 2007 @SmOke_N #include <array.au3> Dim $MyString1 $MyString1 = "junk blah blah blah 192.168.1.1 and other junk 32522344 68.3.1.1 my04 22dd---48s9s 100.260.2.4 300.22.22.1" $answer5 = StringRegExp($MyString1,'((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))',3) For $i = UBound($answer5) -1 to 0 step - 1 ;MsgBox(0,"mod $i",Mod($i,5) & " : " & $answer5[$i]) if Mod($i,5) <> 4 Then _ArrayDelete($answer5,$i) EndIf Next _ArrayInsert($answer5,0,UBound($answer5)) _arraydisplay($answer5,"$answer5") Here is an other one I grabbed somewhere. Enjoy !! ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 23, 2007 Author Moderators Share Posted January 23, 2007 @SmOke_N#include <array.au3> Dim $MyString1 $MyString1 = "junk blah blah blah 192.168.1.1 and other junk 32522344 68.3.1.1 my04 22dd---48s9s 100.260.2.4 300.22.22.1" $answer5 = StringRegExp($MyString1,'((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))',3) For $i = UBound($answer5) -1 to 0 step - 1 ;MsgBox(0,"mod $i",Mod($i,5) & " : " & $answer5[$i]) if Mod($i,5) <> 4 Then _ArrayDelete($answer5,$i) EndIf Next _ArrayInsert($answer5,0,UBound($answer5)) _arraydisplay($answer5,"$answer5")oÝ÷ Øw«z+azº'x+i¶ÞvÊ&{^á'·ß}鶷±þ«¨µí÷Þéín*ݲ«xay%¢,)Ê«²Z(Çè®+b«-®)à'¢b¢wbv}ý¶ØbKhvajÙ¢è¬ë-z+az»Ú'Z¶)දjXܨ®ö¥Öx-ãÓDay0¯z¼+¢×«pjƵêì¢g)à)¶¬¶.®¶sb6æ6ÇVFRfÇC¶'&æS2fwC°¢b33c·57G&ærÒgV÷C¶§Væ²&Æ&Æ&Æ"ãcããæB÷FW"§Væ²3#S##3CBcã2ãã×B#&FBÒÒÓC32ã#cã"ãB3ã#"ã#"ãgV÷C°¢b33c¶Òõ7G&ætvWD'&b33c·57G&ær¥ô'&F7Æb33c¶Âb33²b33² ¤gVæ2õ7G&ætvWD'&b33c·57G&ær Æö6Âb33c¶'&Ò7G&æu&VtWb33c·57G&ærÂgV÷C²#U³ÓUÒb3#²çÃ%³ÓEÒb3#¶Bb3#²çÃb3#¶Bb3#¶Bb3#²çųÓÒb3#¶Bb3#²çųÓÒb3#²â³7Ò#U³ÓU×Ã%³ÓEÒb3#¶GÃb3#¶Bb3#¶GųÓÒb3#¶GųÓÒgV÷C²Ã2 bæ÷B4'&b33c¶'&FVâ&WGW&â6WDW'&÷"ÂÂb33²b33² Æö6Âb33c¶öÆD'& f÷"b33c¶42ÒFòT&÷VæBb33c¶'&Ò7FW0 b33c¶öÆD'&f׳Òb33c¶'&²b33c¶45Òfײ6" æW@ bb33c¶öÆD'&FVâ&WGW&â7G&æu7ÆB7G&æuG&Õ&vBb33c¶öÆD'&ÂÂ6" &WGW&â6WDW'&÷""ÂÂb33²b33²¤VæDgVæ0 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ReverendJ1 Posted January 29, 2007 Share Posted January 29, 2007 @SmOke_N: I cannot seem to get this to work. I get the same thing whether it is a good IP or not. Am I missing something? Maybe you could provide an easy to follow sample. Thank you. BTW, you may want to turn turn off smileys on your first post. I don't think you wanted a frowny face in the middle of your code. :-) expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=G:\My Programs\Daylight Saver\frmIPRange.kxf $frmIPRange = GUICreate("Day Saver", 219, 113, 193, 115) $inputIPRangeBegin = GUICtrlCreateInput("", 8, 40, 89, 21) $inputIPRangeEnd = GUICtrlCreateInput("", 120, 40, 89, 21) GUICtrlCreateLabel("Please enter a valid IP range", 8, 16, 140, 17) GUICtrlCreateLabel("to", 104, 43, 13, 17) $btnIPRangeOK = GUICtrlCreateButton("OK", 72, 72, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnIPRangeOK $boolIPOK = 1 $strIPRangeBegin = GUICtrlRead($inputIPRangeBegin) _StringIPTypeValid($strIPRangeBegin) If @error = 1 Then $boolIPOK = 0 MsgBox(16,"Day Saver", "Please input a valid beginning IP address in the form of xxx.xxx.xxx.xxx") EndIf $strIPRangeEnd = GUICtrlRead($inputIPRangeEnd) _StringIPTypeValid($strIPRangeEnd) If @error = 1 Then $boolIPOK = 0 MsgBox(16,"Day Saver", "Please input a valid ending IP address in the form of xxx.xxx.xxx.xxx") EndIf If $boolIPOK = 1 Then GUIDelete($frmIPRange) ExitLoop EndIf EndSwitch WEnd ; IP Validater thanks to SmOke_N on the AutoIT forums Func _StringIPTypeValid($sIP) If StringRegExp($sIP, "(?:(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.)){3}(?:(25[0-5]$|2[0-4]\d$|1\d{2}$|[1-9]\d$|\d$))") Then Return 1 Return SetError(1, 0, 0) EndFunc Link to comment Share on other sites More sharing options...
Locodarwin Posted January 29, 2007 Share Posted January 29, 2007 http://www.regular-expressions.info/regexb...atecapture.html-S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 30, 2007 Author Moderators Share Posted January 30, 2007 (edited) Just saw this... I stripped the white spaces from your GUICtrlRead() as you didn't provide the "valid" ip addresses you were doing the range on. I used 192.168.0.1 To 192.168.0.255 and it worked fine. expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=G:\My Programs\Daylight Saver\frmIPRange.kxf $frmIPRange = GUICreate("Day Saver", 219, 113, 193, 115) $inputIPRangeBegin = GUICtrlCreateInput("", 8, 40, 89, 21) $inputIPRangeEnd = GUICtrlCreateInput("", 120, 40, 89, 21) GUICtrlCreateLabel("Please enter a valid IP range", 8, 16, 140, 17) GUICtrlCreateLabel("to", 104, 43, 13, 17) $btnIPRangeOK = GUICtrlCreateButton("OK", 72, 72, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnIPRangeOK $boolIPOK = 1 $strIPRangeBegin = StringStripWS(GUICtrlRead($inputIPRangeBegin), 8) _StringIPTypeValid($strIPRangeBegin) If @error = 1 Then $boolIPOK = 0 MsgBox(16,"Day Saver", "Please input a valid beginning IP address in the form of xxx.xxx.xxx.xxx") EndIf $strIPRangeEnd = StringStripWS(GUICtrlRead($inputIPRangeEnd), 8) _StringIPTypeValid($strIPRangeEnd) If @error = 1 Then $boolIPOK = 0 MsgBox(16,"Day Saver", "Please input a valid ending IP address in the form of xxx.xxx.xxx.xxx") EndIf If $boolIPOK = 1 Then MsgBox(64, 'Info', 'Valid IP') GUIDelete($frmIPRange) ExitLoop EndIf EndSwitch WEnd ; IP Validater thanks to SmOke_N on the AutoIT forums Func _StringIPTypeValid($sIP) If StringRegExp($sIP, "(?:(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.)){3}(?:(25[0-5]$|2[0-4]\d$|1\d{2}$|[1-9]\d$|\d$))") Then Return 1 Return SetError(1, 0, 0) EndFunc Edited January 30, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ReverendJ1 Posted February 9, 2007 Share Posted February 9, 2007 Do I need the beta for this or something? I am using 3.2.0.1. I copied your code and it didn't work. Same thing, It always bounces back as invalid. Sorry about the late reply, I am not getting my e-mail notifications for some reason. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 9, 2007 Author Moderators Share Posted February 9, 2007 (edited) Do I need the beta for this or something? I am using 3.2.0.1. I copied your code and it didn't work. Same thing, It always bounces back as invalid. Sorry about the late reply, I am not getting my e-mail notifications for some reason.I wrote it using 3.2.2.0, I have no idea if StringRegExp was broken in 3.2.0.1. But, again you've not posted what you are trying to do (An actual IP range you are putting in). I took the spaces out of the GUICtrlRead() in the last example just to make sure you weren't using them. Every time I've ran it, it's been fine. Edited February 9, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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