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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Machines IP Address

Machines IP Address

Scheduled Pinned Locked Moved C#
csharpquestion
3 Posts 2 Posters 2 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
    Dylan van Heerden
    wrote on last edited by
    #1

    I want to know how I can set my machines IP address in c# coding?;) Sweet

    H 1 Reply Last reply
    0
    • D Dylan van Heerden

      I want to know how I can set my machines IP address in c# coding?;) Sweet

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There's nothing in the .NET FCL that allows you to set your machine's IP address. In fact, it's not a good idea to, anyway. It's not like some user preference that could be changed often. In any case, such an API is not documented in the Platform SDK. Obviously there's some way to do it, but that doesn't mean it's documented. If you want to get the machine's IP address, a simple way is like so:

      string name = Environment.MachineName;
      IPHostEntry host = Dns.GetHostByName(name);
      foreach (IPAddress address in host.AddressList)
      if (address.AddressFamily == AddressFamily.InterNetwork)
      return address;
      return null;

      This would get the IPv4 address, for example.

      Microsoft MVP, Visual C# My Articles

      D 1 Reply Last reply
      0
      • H Heath Stewart

        There's nothing in the .NET FCL that allows you to set your machine's IP address. In fact, it's not a good idea to, anyway. It's not like some user preference that could be changed often. In any case, such an API is not documented in the Platform SDK. Obviously there's some way to do it, but that doesn't mean it's documented. If you want to get the machine's IP address, a simple way is like so:

        string name = Environment.MachineName;
        IPHostEntry host = Dns.GetHostByName(name);
        foreach (IPAddress address in host.AddressList)
        if (address.AddressFamily == AddressFamily.InterNetwork)
        return address;
        return null;

        This would get the IPv4 address, for example.

        Microsoft MVP, Visual C# My Articles

        D Offline
        D Offline
        Dylan van Heerden
        wrote on last edited by
        #3

        Thank you very much.:):-D Sweet

        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