Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:21:18+00:00 2026-05-13T09:21:18+00:00

Hey all. I have written a program that sequentially scans certain parts of a

  • 0

Hey all. I have written a program that sequentially scans certain parts of a LAN for computers (code will be provided). However, when I run this code, it only returns the DNS HostName of the computer it is running on. I looked into using WMI, but I cannot, as I will not always have priveleges to the computers being found. Is there any other way to find a local computers HostName?

using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace CheckLocalNetwork
{
    class PingCheck
    {
        public static string fullip;

        public void CheckSequentialIP()
        {
            IPHostEntry IpEntry = Dns.GetHostEntry(fullip);

            Ping pingSender = new Ping();

            PingOptions options = new PingOptions();
            options.DontFragment = true;

            string data = "a";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            PingReply reply = pingSender.Send(fullip, timeout, buffer, options);

            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine("Address: {0}", reply.Address.ToString());
                Console.WriteLine("Host Name: {0}", IpEntry.HostName);
                Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
                Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
                Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
                Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
                Console.WriteLine("");
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Press enter to search for ip adresses that begin with 192.168.1");
            Console.ReadLine();

            for (int endofip = 1; endofip < 101; endofip++)
            {
                fullip = "192.168.1." + Convert.ToString(endofip);
                PingCheck checkfullip = new PingCheck();
                checkfullip.CheckSequentialIP();

            }
            Console.ReadLine();
    }

All help is much appreciated.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:21:19+00:00Added an answer on May 13, 2026 at 9:21 am

    Hmm – your code sample behaves as expected on my machine – i.e. it returns the hostname of the machine being scanned.

    To investigate your problem deeper, have you tried using nslookup to check the ip addresses resolve?

    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\Rob>nslookup                  <-- type this at a command prompt
    Default Server:  mydns.mydomain.co.uk  <--- these two lines indicate the dns server being used to resolve your queries
    Address:  192.168.0.1                  <----|
    
    > 192.168.0.5                          <---- type in the ip address of one of the machines in question
    Server:  mydns.mydomain.co.uk
    Address:  192.168.0.1
    
    Name:    myworkstation.mydomain.co.uk  <---- this is the hostname, as reported by the DNS using a reverse lookup
    Address:  192.168.0.5
    

    If this doesn’t return the machine name, then you may have a name resolution issue that is not related to your code.

    If this all looks ok, then it might also be worth enumerating the IpEntry.Aliases collection. Are there any entries here, and do they make sense?

    Finally – is the code you have above exactly the code that is going wrong for you, or is it a “distilled” example? The reason I ask is that the documentation for Dns.GetHostEntry states

    “When an empty string is passed as the
    host name, this method returns the
    IPv4 addresses of the local host.”

    I also notice you’re holding “fullip” in a static. If this is not the exact code that is causing the problem, especially if this runs multithreaded, is there a chance you are not initialising “fullip” before the Dns.GetHostEntry is called?

    I may be way off, but I thought is was worth giving a brain dump of what occured to me as I looked at your problem 🙂

    [EDIT:] – your comment to kdt has clarified something I misunderstood. I thought you were saying you always got back the hostname for your local machine, no matter which machine you “scanned” – which is very odd behaviour. In fact I think you are saying you just get back IP addresses for other machines (their IP address), and only get a hostname for your local. Disregard my last bit about the threading and the empty argument.

    This is far more easily explained – your machine is almost certainly just not able to resolve the machine names – I expect my nslookup test I suggested will not return the machine names either.

    In order to resolve these IP’s to host names, your machine needs a DNS that has entries for these machines, or to have them in its local hosts file; your machine isn’t actually asking the remote machine for its name when you do this call so it won;t be able to find it out without help from one of its usual name resolution paths.

    It works for me, because my local DNS really does have entries for all the machines on my network, resolving their host names to ip addresses and vice-versa.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, beginner here. I have written a program that outputs files to .txt's
Hey all. I have a project that will require user input of anywhere from
Hey all, this is the code i have to check for a day thats
Hey all. Here is the scenario. I have the below code, and I'm needing
Hey all, I'm about to rip my hair out. I have this client that
Hey all, i have made a simple form that mimiks the jQuery GROWL effect
hey all. I have a table in my DB that has about a thousand
Hey all, i have converted some C# PayPal API Code over to VB.net. I
Hey all. I have a server written in java using the ServerSocket and Socket
hey stackoverflowers. im having a few problems with the code i have written to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.