2017-08-30 52 views
0

我定義IP頭和有效載荷,我不知道如何增加有效載荷到數據包併發送數據包到服務器。問題與發送數據包

我試試這個,但我得到的錯誤:

IPPACKETNAME() + PayLoad 

回答

0

不知道這是否適用於你的情況不知道更多,但這裏是發送POST請求到服務器的功能。 requests.post可以更改爲您需要的任何類型的請求。例如

requests.get

requests.put

import requests 
def PostRequest(url,data1): 
    r=requests.post("'"+url+"'",data=data1) 
    return r.content 

用法:

response= PostRequest("http://192.168.1.7","DATA") 

EDIT

這是一些代碼發送一個原始數據包噸一臺服務器。

import socket 
import sys 

# Create a TCP/IP socket 
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# Connect the socket to the port where the server is listening 
server_address = ('localhost', 80) 
#print >>sys.stderr, 'connecting to %s port %s' % server_address 
sock.connect(server_address) 



    # Send data 
    message = input() 
    message = str(message).encode() 
    print('sending "%s"' % message) 
    sock.sendall(message) 

    # Look for the response 
    amount_received = 0 
    amount_expected = len(message) 


    data = sock.recv(16) 
    amount_received += len(data) 
    print('received "%s"' % data) 


    print('closing socket') 
    sock.close()