# what function to use?

## Recommended Posts

```\$IP = "100.200.50.25"
\$IP1 = ; result need to be 100
\$IP2 = ; result need to be 200
\$IP3 = ; result need to be 50
\$IP4 = ; result need to be 25
\$decIP = (\$IP1*256*256*256)+(\$IP2*256*256)+(\$IP3*256)+\$IP4
MsgBox(0, "Decimal IP is:", \$decIP)```

##### Share on other sites

I was afraid that someone will answer me like that.

##### Share on other sites

You need something like this

```#include <Array.au3>

\$IP = "100.200.50.25"
\$temp=StringRegExp(\$IP,"(\d{0,3})\.(\d{0,3})\.(\d{0,3})\.(\d{0,3})",3)
_ArrayDisplay(\$temp,"")
\$IP1 =\$temp[0] ; result need to be 100
\$IP2 =\$temp[1] ; result need to be 200
\$IP3 =\$temp[2] ; result need to be 50
\$IP4 =\$temp[3] ; result need to be 25
\$decIP = (\$IP1*256*256*256)+(\$IP2*256*256)+(\$IP3*256)+\$IP4
MsgBox(0, "Decimal IP is:", \$decIP)

Exit```

Or maybe next example will be more simple

```#include <Array.au3>
#include <String.au3>

\$IP = "100.200.50.25"
\$temp=StringSplit(\$IP,'.')
_ArrayDisplay(\$temp,"")
\$IP1 =\$temp[1] ; result need to be 100
\$IP2 =\$temp[2] ; result need to be 200
\$IP3 =\$temp[3] ; result need to be 50
\$IP4 =\$temp[4] ; result need to be 25
\$decIP = (\$IP1*256*256*256)+(\$IP2*256*256)+(\$IP3*256)+\$IP4
MsgBox(0, "Decimal IP is:", \$decIP)

Exit```
Edited by Eugenii

thanks

##### Share on other sites

Why do you need an example for StringSplit or StringRegExp? Have a look in the help file and you will see how the function works (means: example included)!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:

##### Share on other sites

I was afraid that someone will answer me like that.

##### Share on other sites

```; http://www.autoitscript.com/forum/topic/124279-ipv4toint/
; Example 1. use google IP
\$_Ipv4ToInt = _Ipv4ToInt("173.194.66.94")
MsgBox(0,"_Ipv4ToInt",\$_Ipv4ToInt)
ShellExecute("http://" & \$_Ipv4ToInt)

; Example 2. Use int generated from _Ipv4ToInt
\$_IntToIpv4 = _IntToIpv4(\$_Ipv4ToInt)
MsgBox(0,"_IntToIpv4",\$_IntToIpv4)
ShellExecute("http://" & \$_IntToIpv4)
;=============================================================================
;                        Converts an Int into an IP
;=============================================================================
Func _IntToIpv4(\$_Int)
\$oct1 = \$_Int / 16777216
\$_Int = Mod(\$_Int, 16777216)
\$oct2 = Int(\$_Int) / 65536
\$_Int = Mod(\$_Int, 65536)
\$oct3 = \$_Int / 256
\$_Int = Mod(\$_Int, 256)
\$oct4 = \$_Int
\$sIP = Int(\$oct1) & "." & Int(\$oct2) & "." & Int(\$oct3) & "." & Int(\$oct4)
Return String(\$sIP)
EndFunc   ;==>_IntToIpv4

;=============================================================================
;                         Converts an IP into an int
;=============================================================================
Func _Ipv4ToInt(\$_IP)
\$aIP = StringSplit(\$_IP, ".", 3)
\$oct1 = Int(\$aIP[0]) * (256 ^ 3)
\$oct2 = Int(\$aIP[1]) * (256 ^ 2)
\$oct3 = Int(\$aIP[2]) * (256)
\$oct4 = Int(\$aIP[3])
\$iInt = \$oct1 + \$oct2 + \$oct3 + \$oct4
ConsoleWrite (\$iInt & @CRLF)
Return \$iInt
EndFunc   ;==>_Ipv4ToInt```

Edited by JohnOne

Monkey's are, like, natures humans.

##### Share on other sites

Yet another example with StringRegExp

```\$IP = "100.200.50.25"
\$Array_IP = StringRegExp(\$IP, '([^.]+)', 3)
\$IP_Dec = 0
For \$i = 0 To 3
\$IP_Dec += \$Array_IP[\$i] * (256 ^ (3 - \$i))
Next

MsgBox(64, "Decimal IP is:", \$IP_Dec)```

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool.

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. Restrict text in an Edit Control through a Regular Expression.

##### Share on other sites

Or use this function from the Wiki that converts the IP address into an array with each octet in its own element and the hexidecimal value of the IP in another.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

## Create an account

Register a new account