0
Hello,
I have a TXT file containing 340,000 lines of decimal IP addresses, for example: 16777262. Using the ipaddress module I can convert the decimal to the punctuated format '1.0.0.46'. As evidence below:
>>> ipaddress.ip_address(16777262).__str__()
'1.0.0.46'
When I create the code for Python to read each line and convert the decimal to IP, I’m getting the following error:
Code:
import ipaddress
source_file = open('dcim_to_ip.txt')
for decimal_line in source_file:
decimal = decimal_line.rstrip('\n')
ipaddress.ip_address(decimal).__str__()
Error:
ValueError: '16777262' does not appear to be an IPv4 or IPv6 address
I feel like I’m doing something wrong in the way the information is read from the TXT file and passed to the ipaddress module. How can I advance here?