This project is read-only.

Convert String To IPv4 Address? - Beginner Help

Feb 14, 2012 at 4:01 PM
Edited Feb 14, 2012 at 4:29 PM

Hello.  I am very new to C# programming and am trying to learn about sending packets and such.  The "Sending Packets" tutorial you have on this site has been greatly helpful, but unfortunately I am having trouble finding out how/if it is possible to convert a string to an IPv4 Address for Pcap.  I have a string array with an IP address in some, but I cannot figure out how to do a send using that (trying to use that as the address in the send tutorial for a broadcast)..  I thought I had it working, but it keeps giving me this error:

Cannot implicitly convert type 'string' to 'PcapDotNet.Packets.IpV4.IpV4Address'

I tried converting the string to a 'System.Net.IPAdress', but that also gave me the same is the code I have right now (just been trying random things I find on Google so far):

                    // Set IPv4 parameters
                    IPAddress address = IPAddress.Parse(stringarray[1]);
                    ipV4Layer.Destination = address;
                    ipV4Layer.Identification = (ushort)i;

I am completely lost here; can anyone explain why this won't work/what I need to change?  Thank you for your help, and have a great day.


Brendan "NinjaNife" West



I figured it out..I accidentally deleted the 'new IpV4Address()' part without noticing and that completely screwed it up.  It now works like this:

                    ipV4Layer.Destination = new IpV4Address(stringarray[1]);
ipV4Layer.Identification = (ushort)i;

Sorry for the inconvenience; glad I finally got past this lol.