2016-11-19 24 views
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地址時,它運行良好,但是當我從原始輸入存儲它時,它會給我提供錯誤。

回答

0

我認爲這是由於您不是從raw_input轉義回車符(\ n或\ r \ n): output01 = output01.strip('\ t \ n \ r') 可能會訣竅。

雖然你應該考慮檢查Scapy的那種東西。

相關問題