# Excel Based IP Functions

Senior Solution Architect at Ericsson
Jul. 28, 2012
1 of 33

### Excel Based IP Functions

• 1. IP Functions Introduction ipfx@rajivbhardwaj.com
• 2. Version Details Version Date Edited by Section/s Comments 1.0 22-02-2012 Rajiv Bhardwaj All First Draft 1.1 19-06-2012 Rajiv Bhardwaj All Added four more functions, Removed “RB_” prefix from function names
• 3. Purpose: Provide Introduction to Excel based IP functions created by me. Provide Instructions for Installation and operating the IP Functions . Scope: Provide Excel based IP functions for easier IP Planning. Provide Excel based IP functions for creating automated templates.
• 4. Motivation After I got tired with manually modifying IP address in excel, I decided to give a try to creating some kind of formulae. I got some success with inbuilt “left” & “right” functions. e.g. by using something like this to increment the IP address at position A1. LEFT(A1,FIND(“.”,A1,FIND(“.”,A1,FIND(“.”,A1,1)+1)+1))&RIGHT(A1,LEN(A1)-FIND_ (“.”,A1,FIND(“.”,A1,FIND(“.”,A1,1)+1)+1))+1
• 5. Limitation of using Formulae But soon it became quite cumbersome because of 3 reasons. 1. Every time I wanted to use this formula I had to change the reference cell ID “A1″ manually. It defeated the original purpose of automation. 2. It didn’t work well for changing the Class A or B IP Subnets i.e. updating any of the first three “parts” of IP address. 3. As I started working on some IP hungry nodes. Handling of huge number of IPs became almost impossible by this method. To overcome these limitations I tried to create VBA based functions which are easier to use and provide more functionalities. I didn’t have much experience with macros and VBA, but still was able to create a set of working functions.
• 6. IP Functions I have complied all the IP address related functions in Add-in format. This way it is easy to share all the functions without much effort on the end user part. Although, .xla format is not fully portable as excel sheets created by one user cannot be used by another user without updating the links. But it’s the easiest way to transfer reusable functions. This Add-in RBIPFx include following functions in present version (0.3). 1. IP_Bits2Mask 2. IP_ErrChk 3. IP_Hosts 4. IP_IP2Mbits 5. IP_Mod 6. IP_NextSub
• 7. IP Functions 7. IP_Bcast 8. IP_Count 9. IP_IsExist 10. IP_Mask2Bits 11. IP_Subnet
• 10. Installing RBIPFx Addin -II For Office 2007 or later: 1. First move the add-in file (“.xla”) to “C:Addins” folder 2. Click on the Office button in top left corner. 3. Then choose excel options.
• 11. Installing RBIPFx Addin -III 4. Select “Add-ins” , choose Manage “Excel Add-ins” and click Go. 5. Then choose the RBIPFx.xla add-in from list and click OK. Add-in will appear in the list if you have copied it to the right Add-in folder as described in step 1.
• 12. Installing RBIPFx Addin -IV 6. If Add-in is not displayed in the list then you can use the browse button to locate the Add-in File. 7. If Add-in is correctly installed then it may show a relevant message. 8. Once installation is complete then you can see the “compatible” add-ins in the Add-ins tab of office ribbon. (Optional)
• 13. FUNCTION DESCRIPTION
• 14. IP_Mod: IP Modification Function IP_Mod: This is the primary function of RBIPFx Excel Add-in. It modifies the IP addresses. Syntax: RB_Mod_IP( IP address, optional Step, Optional Part) Parameters: IP Address: As the name suggest is IPV4 IP address which you want to modify. Step: It is the number by which you want to increment or decrement the given IP address. It is optional and default value of this parameter is 1. Part: It is the part of IP address you want to modify. As IPv4 address as 4 parts separated by “.”. i.e For IP 10.11.12.13, Part 1 =10, part 2=11, Part3 =12 & Part4 =13. It is also optional parameter & default value of this part is 4. i.e. last part (Class C subnet)
• 15. IP_Mod: IP Modification Function - Usage USAGE: Following are some of the ways, this function can be used. i) You can increment the IP by one just by using the IP address parameter. i.e. IP_Mod(“10.11.12.13″,1) will give 10.11.12.14.
• 16. IP_Mod: IP Modification Function - Usage As I have set the value of Step to be 1 by default so IP_Mod(“10.11.12.13″) will also do.
• 17. IP_Mod: IP Modification Function - Usage Dragging this function in excel column will give you a series of IPs.
• 18. IP_Mod: IP Modification Function - Usage But if you want to increment the IP with bigger value then you need to use the parameter STEP. e.g IP_Mod(“10.11.12.13″, 10) will give you 10.11.12.23.
• 19. IP_Mod: IP Modification Function - CIDR IP address with subnet maskbits (e.g. xx.xx.xx.xx/24) is also used in the IP domain This function can handle that too. It automatically detects the subnet mask separator (“/”) and uses the same format for output. e.g IP_Mod(“10.11.12.13/24″,10,3) will give you 10.11.22.13/24 as output.
• 20. IP_Mod: IP Modification Function - Decrement If you want to decrement an IP address instead of incrementing then you can do that too by just giving a negative Step Value. e.g IP_Mod(10.11.12.13, -5) will give 10.11.12.8
• 21. IP_Mod: IP Modification Function - Error Handling Error Handling: It can handle basic error situations. if you input a step value more than 255 or less than -255. Function will return an error. e.g. IP_Mod(10.11.12.13, 258) will give “#NUM” as return. This error is inline with basic excel errors as it signifies that wrong value of number is being used.
• 22. IP_Mod: IP Modification Function - Error Handling I initially had pop-up message for such situations but it becomes quite irritating if we have a large sheet full of IP addresses. One more situation which I have captured is that sometimes input is well within range but the resultant IP is out of range. It also generates error in such situation. e.g. IP_Mod(10.11.12.13, 245) will give “#NUM” error as resultant IP 10.11.12.258 is not the valid one. For me this error functionality is a real life saver as I tend to forget this “255″ limit.
• 23. IP_NextSub: Next Subnet Function This function calculates next IP subnet. Subnet mask is mandatory parameter for this function. This function can also work with CIDR notation. If both CIDR notation and Maskbit parameter are given, maskbit parameter is given higher priority.