in reply to how to send one http request packet over ethernet

Hello and welcome munu,
while I think that in general it should be possible to manually construct HTTP request packets with Net::RawIP, the commonly used way to send HTTP requests is through LWP::UserAgent, or if the website you are querying needs more interaction, WWW::Mechanize.

Maybe we can help you better if you tell us more exactly what you want to do and what you have tried so far. How (not) to ask a question has many helpful hints on how to formulate your question and on what to post.

  • Comment on Re: how to send one http request packet over ethernet

Replies are listed 'Best First'.
Re^2: how to send one http request packet over ethernet
by Anonymous Monk on Jul 28, 2004 at 11:35 UTC
    chiburashka is not new, new username, same luser
Re^2: how to send one http request packet over ethernet
by munu (Novice) on Jul 28, 2004 at 11:14 UTC
    Actually i want to construct different IP packets like (DHCP discovery, HTTP request/response,...) and send it to servers so that i can simulate a protocol client to a certain extent..(for ex. for dhcp discover packet sent I am getting any dhcp reply or not).

    My overall need is to send different packets(DHCP, HTTP, ARP, PING, etc..) from the program..capturing the replies(packets) for those packets if any..And i should be able to modify the captured packets and again sent back to any other host..
    ------------------------------------------------------------
    Till now I know how to generate and send udp/tcp/icmp packets with NET::RawIP module..But I am not able to construct packets above TCP/UDP(DHCP, HTTP, etc..).
    Also I need to know how to capture packets from ethernet, modify them and again send on the ethernet..
    ------------------------------------------------------------
    thanks and regards
    MUNU

      You will need to learn about the differences between the different network protocols and the different layers at which these protocols live. The ISO network layers are the most common way to speak about the different layers.

      In your list, you named three kinds of protocols that live on three different layers:

      IP packets live at the Network Layer (layer 3). Those are the most basic building blocks you will need and what Net::RawIP provides. As these are really low level, anything is possible, but everything will be hard, as you will basically have to reimplement your whole TCP stack yourself.

      ARP, ICMP/PING, TCP, UDP: These protocols live on the ISO network layer 4, the transport layer. The packets here consist of one or more IP packets. You will have to learn about the structure of the packets for each protocol and then construct these packets yourself. I recommend starting with the ICMP ("PING") packets, as these are part of a very simple and easy to manage protocol with one ICMP packet corresponding to one IP packet in most cases, so you don't have to deal with fragmentation and reassembly.

      On top of UDP and TCP, there are other protocols which then live at the application layer. DHCP and HTTP live here. If you want to start with the easiest things first, you should start here as well, and learn about the structure of the protocols and requests and answers. Communications at this level do not happen in terms of packets anymore, as you can continouusly read and write data over the connection and you won't notice that there are TCP/IP packets underneath.

      Personally, I can only recommend to you to start with HTTP capturing as this is the most easy thing to test.

      For sniffing and manipulating, there is libpcap and Net::PCap plus Net::PCapUtils, but these require you to know a lot about the protocols to be manipulated and sniffed. This is not easy.

      have you looked at using nemesis - I think it is on sourceforge and I have used it with some shell scripts to construct packets on the fly - works like a charm !!!
      The HTTP part of the packets is relatively easy. Just put the HTTP request in the payload. The hard part is doing TCP. This requires sending the packets to initiate the connection, and handling all the details of windows, flow control. Servers are not going to accept HTTP requests that don't come as part of a valid TCP connection.

      Code to do this is already written. It is in the operating system in the network stack. For TCP protocols, making a normal connection is the way to go.

      You could reimplement TCP/IP in Perl. That would be cool, but is a lot of work. You will need to learn a lot of networking to do it.