How to change IP-adress in a proceeding package?

Nov 8, 2010 at 7:00 PM
Edited Nov 8, 2010 at 7:32 PM

Good afternoon.

Tell to me, please, how to change IP-adress in the received UDP package, and send it further?

Thanks for the help! (P.S. Sorry about my English)

Nov 8, 2010 at 8:00 PM

Hi SnakeDJ,


You should simply extract the different layers of the packet (packet.Ethernet.ExtractLayer(), packet.Ethernet.IpV4.ExtractLayer() ...), change the ones you want different and then use PacketBuilder to build a new packet from the new Layers.

Sending the new packet is done using a PacketCommunicator.



Nov 8, 2010 at 8:30 PM
Edited Nov 8, 2010 at 8:47 PM

Then tell to me, please, correctly I have made a code? (VB.NET 2010)


Dim selectedDevice As PacketDevice = allDevices(1)
        Using communicator As PacketCommunicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)
            Dim packet As Packet
            communicator.SetFilter("udp and host")
                Dim result As PacketCommunicatorReceiveResult = communicator.ReceivePacket(packet)
                    Dim ethernetLayer = DirectCast(packet.Ethernet.ExtractLayer(), EthernetLayer)
                    Dim ipV4Layer = DirectCast(packet.Ethernet.IpV4.ExtractLayer(), IpV4Layer)
                    Dim udpLayer = DirectCast(packet.Ethernet.IpV4.Udp.ExtractLayer(), UdpLayer)
                    ipV4Layer.Destination = New IpV4Address("")
                    Dim targetPacket = PacketBuilder.Build(packet.Timestamp, ethernetLayer, ipV4Layer, udpLayer, packet.Ethernet.IpV4.Udp.Payload.ExtractLayer())
                End If
        End Using


The program receives packages, however refuses to send them. I use external Sniffer for tracking the packets

Help Please!

Nov 11, 2010 at 5:30 PM

Please, answer me! It is very important

Nov 28, 2010 at 10:13 AM

Your code looks correct to me (I'm not much of VB.NET developer though).

Have you checked if it actually works (by sniffing its output using Wireshark for example)?


Dec 6, 2010 at 12:23 PM

Hi SnakeDJ,

As far as I know (I am doing the same as you) you also need the new IP Mac Address and you must also recalculate IP layer header checksum.

ethernetLayer.Destination = <new IP MAC address>
ipV4Layer.HeaderChecksum = null

As retrieving the MAC address of an IP involves preparing an ARP packet and this is not trivial (look for help in google, but you will find mostly protocol specifications) I suggest you to use a hardcoded one, like new MacAddress("AB:CD:EF:11:22:33"). Anyway, if you know the IP address, chances are that you also know the Mac Address. If not... good luck with your ARP request - response :-)

Jan 23, 2011 at 4:29 PM

Here is a Function to retrieve the Mac from the arp cache  so you just need to send the arp request

rivate Function getMacFromArpCache(ByVal ip As IpV4Address) As MacAddress
        Dim ips As String = ip.ToString

        Dim cmd As New ProcessStartInfo With {
         .FileName = "arp",
         .Arguments = "-a",
         .UseShellExecute = False,
         .RedirectStandardOutput = True,
         .CreateNoWindow = True
        Dim tmp As Process = Process.Start(cmd)
        Dim resultado As IO.StreamReader = tmp.StandardOutput

        Dim str As String = ""
        While resultado.EndOfStream = False
            str = resultado.ReadLine
            If str.Contains(ips) Then Exit While Else If resultado.EndOfStream Then Return MacAddress.Zero
        End While
        str = str.Trim
        str = str.Substring(ips.Length)
        str = str.Trim()
        str = str.Substring(0, 17)
        str = str.Trim()
        str = str.Replace("-"c, ":")
        Return New MacAddress(str)
    End Function



and the request :

 Public Sub SendARP_request(ByVal dst As IpV4Address)       

        Dim LayerEthernet As New EthernetLayer With {
            .EtherType = EthernetType.Arp,
            .Destination = New MacAddress("ff:ff:ff:ff:ff:ff"),
            .Source = mymac

        Dim LayerArp As New Arp.ArpLayer With {
            .Operation = Arp.ArpOperation.Request,
            .ProtocolType = EthernetType.IpV4,
            .SenderHardwareAddress = conversorMac.Invoke(mymac.ToString.Split(":")),
            .SenderProtocolAddress = conversorIp.Invoke(miip.ToString.Split(".")),
            .TargetHardwareAddress = conversorMac.Invoke("00:00:00:00:00:00".Split(":")),
            .TargetProtocolAddress = conversorIp.Invoke(dst.ToString.Split("."))

        builder = New PacketBuilder(LayerEthernet, LayerArp)
    End Sub