Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Raw IP Address

C# Raw IP Address

Scheduled Pinned Locked Moved C#
csharpjavaquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DwR
    wrote on last edited by
    #1

    Hi, Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress(); I've not done anything with networking in C# before but from an admittedly quick inspection it does appear that the java implementation makes more intuitive sense. I'd say it's more feature rich too but I haven't ben able to make complete sense yet of what C# has to offer. Regards, Dave

    Regards, Dave

    P 1 Reply Last reply
    0
    • D DwR

      Hi, Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress(); I've not done anything with networking in C# before but from an admittedly quick inspection it does appear that the java implementation makes more intuitive sense. I'd say it's more feature rich too but I haven't ben able to make complete sense yet of what C# has to offer. Regards, Dave

      Regards, Dave

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      DwR wrote:

      Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress();

      IPAddress address = Dns.Resolve("localhost");

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      D 1 Reply Last reply
      0
      • P Pete OHanlon

        DwR wrote:

        Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress();

        IPAddress address = Dns.Resolve("localhost");

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        D Offline
        D Offline
        DwR
        wrote on last edited by
        #3

        Hi, Thanks for that. A couple of questions / observations: 1. The C# documentation refers to the resolve method as being obsolete. 2. The java type of "address" is byte[]. The method returns a "raw" ip address. The C# equivalents, including Dns.resolve return an IPAddress[] type which i assume isn't raw. Can C# return raw addresses? I assume the type to use is c# byte[]... Additionally, I'm unclear as to what the java documentation means by a raw ip address. Can you clarify? I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation.

        Regards, Dave

        C 1 Reply Last reply
        0
        • D DwR

          Hi, Thanks for that. A couple of questions / observations: 1. The C# documentation refers to the resolve method as being obsolete. 2. The java type of "address" is byte[]. The method returns a "raw" ip address. The C# equivalents, including Dns.resolve return an IPAddress[] type which i assume isn't raw. Can C# return raw addresses? I assume the type to use is c# byte[]... Additionally, I'm unclear as to what the java documentation means by a raw ip address. Can you clarify? I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation.

          Regards, Dave

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          DwR wrote:

          I'm unclear as to what the java documentation means by a raw ip address

          One would presume that the raw IP Address is just the bytes that make up the IP Address - as it would normally be with anything described as raw.

          DwR wrote:

          I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation

          What operation?

          Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog

          D 1 Reply Last reply
          0
          • C Colin Angus Mackay

            DwR wrote:

            I'm unclear as to what the java documentation means by a raw ip address

            One would presume that the raw IP Address is just the bytes that make up the IP Address - as it would normally be with anything described as raw.

            DwR wrote:

            I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation

            What operation?

            Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog

            D Offline
            D Offline
            DwR
            wrote on last edited by
            #5

            Hi, I think I've resolved this. By setting the type as IPAddress the member "GetAddressBytes" can be used to convert the address to bytes matching the type of the variable "address". Thanks for your tip, it pointed me in the right directions. That said, I've hit another problem which seems to be a bit trickier. I need to determine the IP addresses associated with the network interfaces of the multi-homed host the code is running on. I am capturing the available interfaces as follows: NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); I then want to loop through the entries and for each one load it's associated IP Addresses into an IPHostEntry instance (or similar). However, I don't see any way to determine the list of ip addresses associated with a particular network interface returned by the foreach loop as it iterates through "interfaces". How is this done?

            Regards, Dave

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups