0
所以我得到这个:“错误:[错误10049]请求的地址不在其上下文中有效”,试图在我的python脚本发送一个UDP数据包时
Traceback (most recent call last):
File "E:\Demo Stand\test srcipts\attack_PLC.py", line 97, in <module>
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
error: [Errno 10049] The requested address is not valid in its context
这里是我的代码:
import sys
import time
import socket
ans = True
ans1 = True
output01 = ""
UDP_IP = str(output01)##if this is set to something like this "192.168.56.1" instead of output01 it works.
TankID = 0
UDP_PORT = int(TankID)
MESSAGE = "pump on"
MESSAGE2 = "fire"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while ans:
output01 = raw_input("Enter target IP Address:")
TankID = raw_input("Enter target ID:")
TankID = TankID.strip(' \t\n\r')
UDP_PORT = int(TankID)
if output01 == output01 :
print "Target Aquired"
break
while ans1:
output02 = raw_input("Environment Acquired....Press 'Y' to execute: ")
if output02 == 'y':
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
time.sleep(5)
sock.sendto(MESSAGE2, (UDP_IP, UDP_PORT))
break
我不知道它为什么不只是发送数据包。当我将UDP_IP变量设置为任何类似“192.168.56.1”的IP地址时,它运行良好,但是当我从原始输入存储它时,它会给我提供错误。