BlueKit Posted October 3, 2010 Share Posted October 3, 2010 Hi all, I write an ip address in a GUI, or i read this IP on SQLite ex : $IPAddress=192.168.2.200 (ip of a server) How can i have IP address +10 for configure the host ex : 192.168.2.210 Thanks for your help Link to comment Share on other sites More sharing options...
Mat Posted October 3, 2010 Share Posted October 3, 2010 Use StringSplit to split the IP address into its parts, then add ten to the last one $asSplit = StringSplit($IPAddress, ".") $asSplit[4] += 1 $IPAddress = $asSplit[1] & "." & $asSplit[2] & "." & $asSplit[3] & "." & $asSplit[4] AutoIt Project Listing Link to comment Share on other sites More sharing options...
Calistoga Posted October 3, 2010 Share Posted October 3, 2010 As Mat said MsgBox(64, "IP Increment", _IP_Add("192.168.2.200", 10)); Func _IP_Add($s_IP = "192.168.2.200", $i = 10) Local $a_parts = StringSplit($s_IP, ".", 0); If (IsArray($a_parts) = 0 Or $a_parts[0] <> 4) Then Return SetError(1, 0, ""); $a_parts[4] += $i; $s_IP = $a_parts[1] & "." & $a_parts[2] & "." & $a_parts[3] & "." & $a_parts[4]; Return SetError(0, 0, $s_IP); EndFunc ;==>_IP_Add Link to comment Share on other sites More sharing options...
BlueKit Posted October 3, 2010 Author Share Posted October 3, 2010 Thanks for yours answers Link to comment Share on other sites More sharing options...
Mat Posted October 3, 2010 Share Posted October 3, 2010 Just in case you need this, it adds it up properly, so '0.0.0.0 + 256' = '0.0.1.0'. MsgBox(64, "IP Increment", _IP_Add("192.168.2.200", 60)) Func _IP_Add($s_IP, $i) Local $a_parts = StringSplit($s_IP, ".", 0) If Not IsArray($a_parts) Or $a_parts[0] <> 4 Then Return SetError(1, 0, "") ; Incorrect input. $a_parts[4] += $i For $n = 4 To 1 Step -1 $a_parts[$n - 1] += Floor($a_parts[$n] / 256) $a_parts[$n] = Mod($a_parts[$n], 256) Next If $a_parts[0] <> 4 Then Return SetError(2, 0, "") ; Out of range. $s_IP = StringFormat("%.3s.%.3s.%.3s.%.3s", $a_parts[1], $a_parts[2], $a_parts[3], $a_parts[4]) Return $s_IP EndFunc ;==>_IP_Add AutoIt Project Listing 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