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. how to get the hostname of a client pc in my network

how to get the hostname of a client pc in my network

Scheduled Pinned Locked Moved C#
sysadminquestioncsharphelptutorial
2 Posts 2 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.
  • B Offline
    B Offline
    batmanAgen
    wrote on last edited by
    #1

    hi guys, im using c#.. how can i get the hostname of a client pc from the server appliction in my network? i have no problem getting the IP address but i can't get the hostname... tnx in advance..:)

    F 1 Reply Last reply
    0
    • B batmanAgen

      hi guys, im using c#.. how can i get the hostname of a client pc from the server appliction in my network? i have no problem getting the IP address but i can't get the hostname... tnx in advance..:)

      F Offline
      F Offline
      fang_eric
      wrote on last edited by
      #2

      I think the GetHostbyAddress() method can help you. the followed code is copyed from msdn: try { IPAddress hostIPAddress = IPAddress.Parse(IpAddressString); IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress); // Get the IP address list that resolves to the host names contained in // the Alias property. IPAddress[] address = hostInfo.AddressList; // Get the alias names of the addresses in the IP address list. String[] alias = hostInfo.Aliases; Console.WriteLine("Host name : " + hostInfo.HostName); Console.WriteLine("\nAliases :"); for(int index=0; index < alias.Length; index++) { Console.WriteLine(alias[index]); } Console.WriteLine("\nIP address list : "); for(int index=0; index < address.Length; index++) { Console.WriteLine(address[index]); } } catch(SocketException e) { Console.WriteLine("SocketException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch(FormatException e) { Console.WriteLine("FormatException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch(ArgumentNullException e) { Console.WriteLine("ArgumentNullException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch(Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } Just do it!

      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