我正在尝试将IP地址转换为标准点缀的cidr表示法。 我收到的错误表明我需要将sys.argv更改为字符串,但我找不到将其转换为字符串的方法。
#!/usr/bin/python
import re
import sys
import json
import string
import iptools
import os.path
import requests
import subprocess
import socket,struct
from time import gmtime, strftime
label = sys.argv[1]
domain = sys.argv[2]
ipv4 = sys.argv[3]
ipv6 = sys.argv[4]
cidr = socket.inet_aton(ipv4)
cidr.decode('utf-8')
fd = open( domain+".external", 'w')
fd.write(domain+". IN TXT \"v=spf1 mx a ptr ip4:"+cidr+" -all\"\n")
CLI:
[\u@yoda:/usr/local/etc/namedb] # python3.4 makecustdomain.py jolly santa.com 108.61.190.64 2001:19f0:6c00:8141::64
Traceback (most recent call last):
File "makecustdomain.py", line 23, in <module>
fd.write(domain+". IN TXT \"v=spf1 mx a ptr ip4:"+socket.inet_aton(ipv4)+" -all\"\n")
TypeError: Can't convert 'bytes' object to str implicitly
如何将sys.argv中的IP地址转换为cidr表示法?