【发布时间】:2022-01-08 07:17:45
【问题描述】:
我想在 python 命令中传递变量 server 并从命令中读取 python 命令结果 portStatus 变量。
for server in `echo $dnsServers | awk -F";" '{print $1" "$2" "$3" "$4" "$5" "$6}'`
do
python3 -c 'import socket;
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
host=("$server", 53);
portStatus=a_socket.connect_ex(host);'
done
echo $portStatus
收到此错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
Traceback (most recent call last):
File "<string>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
Traceback (most recent call last):
【问题讨论】:
标签: linux sockets networking