You can use the netaddr
Python package.
Example:
>>> n = IPNetwork('10.120.15.1/24')
>>> list(n)[0:3]
[IPAddress('10.120.15.0'), IPAddress('10.120.15.1'), IPAddress('10.120.15.2')]
>>> IPNetwork('10.120.15.1/24').network
IPAddress('10.120.15.0')
>>> str(IPNetwork('10.120.15.1/24').network)
'10.120.15.0'
As for your script, you should be able to perform all of the access list modifications in the same SSH session, rather than one SSH session per address line.
I also suspect that you have inverted the netmask in your access-list
command — it should probably be 255.255.255.0
rather than 0.0.0.255
(see examples).
Furthermore, I see that you are generating many access rules of the same form. That will be difficult to manage. Instead, you should write one access rule that references a network object group. You should only use your script to add/remove members of the group.