Change IP address (solved)

Dear all,

I would like your help with the following:

I want to change the last number of an IP address getting from an excel file, If I have the following coding:

i = device_ipplan_info[0].attr(“IP Address”)
i = 1.1.1.1/30

first I need from python to get only 1.1.1.1
second I need that for the last digit .1 do a sum of +2, the result would be 1.1.1.3

Thanks in advance

@derwindduran Can you show what you have tried so far?

excel_file = u'*excel file*'
controller_file = u'*IPs Controladoras*'
ip_plan_fle = u'*IP PLaning*'
controller_Dict = LOAD_EXCEL_FILE(controller_file, "Sheet1", 1, "key1")
ip_plan_Dict = LOAD_EXCEL_FILE(ip_plan_fle, "Sheet2", 2, "key2")
Site_2G_Dict = LOAD_EXCEL_FILE(excel_file,"Sheet3", 1, "key3")

Base_Station_row_list = []
Site_list = READ_TXT_FILE("site_list")
for sites in Site_list:
    if sites not in Site_2G_Dict.keys(): # Check if SiteID exist in excel file
        print sites, "Not present in Personal excel file"
        continue
		
Site_2G_Info = Site_2G_Dict[sites]
h = Site_2G_Info[0].attr("Key4")

# Device IP Address info
    for device_ip in ip_plan_Dict:
        if device_ip != h: continue
        device_ipplan_info = ip_plan_Dict[device_ip]
        i = device_ipplan_info[0].attr("IP Address")
        x = len(i)

i = 1.1.1.1/30 but I don’t know how to get only 1.1.1.1 and then sum +2 on the last number = 1.1.1.3

@derwindduran Can you show how the Excel file looks like?

Are you coding inside Dynamo? Please tell more about your workflow?

hi salvatore sorry, I’m using pycharm and this is the coding for that part:

> excel_file = u'*Personal SUR GUL EPT 20190103*'
> controller_file = u'*IPs Controladoras*'
> ip_plan_file = u'*IP PLAN South_2*'
> controller_Dict = LOAD_EXCEL_FILE(controller_file, "Sheet1", 1, "key1")
> ip_plan_Dict = LOAD_EXCEL_FILE(ip_plan_file, "Sheet2", 1, "key2")
> Site_2G_Dict = LOAD_EXCEL_FILE(excel_file,"Sheet3", 1, "key3")
> 
> Base_Station_row_list = []
> Site_list = READ_TXT_FILE("site_list")
> for sites in Site_list:
>     if sites not in Site_2G_Dict.keys(): # Check if SiteID exist in excel file
>         print sites, "Not present in Personal excel file"
>         continue
> 		
> Site_2G_Info = Site_2G_Dict[sites]
> h = Site_2G_Info[0].attr("Site ID")
> 
> # Device IP Address info
>     for device_ip in ip_plan_Dict:
>         if device_ip != h: continue
>         device_ipplan_info = ip_plan_Dict[device_ip]
>         i = device_ipplan_info[0].attr("IP Address")
>         x = len(i)

this is the flow:

  1. upload all the necessary excel files that contain all my info: excel_file, controller_file, and ip_plan_file.

  2. from excel_file I take a key named Key3 this will be the main key that I will use to get other info in another column in the same excel related to that key, for example, Site ID = key4.

            `h = Site_2G_Info[0].attr("Site ID")`
    
  3. then with the key4 already identified I will use it to get some IP info inside of the ip_plan_file
    image

        for device_ip in ip_plan_Dict:
            if device_ip != h: continue
                device_ipplan_info = ip_plan_Dict[device_ip]
                i = device_ipplan_info[0].attr("IP Address")
    

Now I do not know how to get only the IP without the mask and then add +2 to the last number to finally get: 1.1.1.3
y = "1.1.1.3" # for example

Sorry I can copy only one image at the time because I’m new user

  1. upload all the necessary excel files that contain all my info: excel_file, controller_file, and ip_plan_file.

image

  1. from excel_file I take a key named Key3 this will be the main key that I will use to get other info in another column in the same excel related to that key, for example, Site ID = key4.

image

    `h = Site_2G_Info[0].attr("Site ID")`

Would this work?

j = i.split("/")[0]
h = j.split(".")
h[-1] = str(int(h[-1])+2)
h = ".".join(h)

Side note, if you have a general understanding of what the task is, you can google to find the appropriate methods. For example, I didn’t know what the command to reconnect a list after splitting it but I knew there is probably a command for it, so I googled “python join list to string” and found the .join() method.

1 Like

Thanks let me try it

Side note, if you have a general understanding of what the task is, you can google to find the appropriate methods. For example, I didn’t know what the command to reconnect a list after splitting it but I knew there is probably a command for it, so I googled “python join list to string” and found the .join() method.

thanks for the advice

Work perfectly thanks a lot for your time

No problem. If the post solved your problem, could you mark it as solved so others know what the solution is and keep the forum organized?

1 Like

done thanks