bjoerni Posted December 24, 2009 Posted December 24, 2009 Hi, i hope you can help me :-) i need for a projekt a ip in decimal http://www.allredroster.com/iptodec.htm so i need a function who do the same as the website. i search for a while but i´m not so good in math... can you help me? bjoerni
Yashied Posted December 24, 2009 Posted December 24, 2009 $sIP = '192.168.4.242' MsgBox(0, '', _IPStrToDec($sIP)) Func _IPStrToDec($sIP) Local $tDWord, $Val = StringSplit($sIP, '.') If $Val[0] < 4 Then Return SetError(1, 0, '') EndIf $Val = BitShift($Val[1], -24) + BitShift($Val[2], -16) + BitShift($Val[3], -8) + $Val[4] $tDWord = DllStructCreate('dword') DllStructSetData($tDWord, 1, $Val) Return DllStructGetData($tDWord, 1) EndFunc ;==>_IPStrToDec Tony4219 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
spudw2k Posted December 24, 2009 Posted December 24, 2009 (edited) Another example. $dec = _IPToDec("10.1.1.1") msgbox(0,"",$dec) Func _IPToDec($ip) $octets = StringRegExp($ip,"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b",1) If UBound($octets) <> 4 Then Return 0 Return Dec(Hex(Int($octets[0]),2) & Hex(Int($octets[1]),2) & Hex(Int($octets[2]),2) & Hex(Int($octets[3]),2)) EndFunc edit: My math may be less efficient, but the regex validates an ip address instead of simply checking for "." separators. Edited December 24, 2009 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Yashied Posted December 24, 2009 Posted December 24, 2009 @spudw2k Nice, but try, for example, with "192.168.4.242". My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
bjoerni Posted December 25, 2009 Author Posted December 25, 2009 (edited) thx mans!!!! but... i have no plan from this function.. how i make it reverse? Edited December 25, 2009 by bjoerni
ProgAndy Posted December 25, 2009 Posted December 25, 2009 (edited) Simple: Func _NumberToIP($nIP) ;Author: Prog@ndy Local $aResult = DllCall('ws2_32.dll', 'str', "inet_ntoa", "ulong", $nIP) If @error Then Return SetError(1,0,'0.0.0.0') Return $aResult[0] EndFunc Func _IPToNumber($sIP) ;Author: Prog@ndy Local $aResult = DllCall('ws2_32.dll', 'ulong', "inet_addr", "str", $sIP) If @error Then Return SetError(1,0,0) Return $aResult[0] EndFunc $IP = "123.456.789.321" $Num = _IPToNumber($IP) $rec = _NumberToIP($Num) MsgBox(0, '', $IP & @CRLF & $Num & @CRLF & $rec) Edited December 25, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
bjoerni Posted December 25, 2009 Author Posted December 25, 2009 Thats false $IP = "123.100.100.100" $IP2 = "123.100.100.101" $Num = _IPToNumber($IP) $rec = _IPToNumber($IP2) MsgBox(0, '', $IP & @CRLF & $Num & @CRLF & $rec) must be: 2070176868 2070176869 but it is a other number...
ProgAndy Posted December 25, 2009 Posted December 25, 2009 (edited) No, its correct but the return-value is network byte order wich is different from host byte order on Windows. One solution is: Func _NumberToIP($nIP, $fHostByteOrder=True) ;Author: Prog@ndy If $fHostByteOrder Then Local $aResult = DllCall('ws2_32.dll', 'ulong', "ntohl", "ulong", $nIP) If @error Then Return SetError(2,0,0) $nIP = $aResult[0] EndIf Local $aResult = DllCall('ws2_32.dll', 'str', "inet_ntoa", "ulong", $nIP) If @error Then Return SetError(1,0,'0.0.0.0') Return $aResult[0] EndFunc Func _IPToNumber($sIP, $fHostByteOrder = True) ;Author: Prog@ndy Local $aResult = DllCall('ws2_32.dll', 'ulong', "inet_addr", "str", $sIP) If @error Then Return SetError(1,0,0) If $fHostByteOrder Then $aResult = DllCall('ws2_32.dll', 'ulong', "ntohl", "ulong", $aResult[0]) If @error Then Return SetError(2,0,0) EndIf Return $aResult[0] EndFunc Edited December 25, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
spudw2k Posted December 26, 2009 Posted December 26, 2009 @spudw2kNice, but try, for example, with "192.168.4.242". yea, those darn 32 bit signed integers. You're right. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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