ASP.NET C# - Find a machine name using IP Address

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smurfas
    New Member
    • Jul 2008
    • 30

    ASP.NET C# - Find a machine name using IP Address

    Hi, everything simple:
    Code:
    string strWhatever = Request.ServerVariables("LOGON_USER");
    TextBox1.Text = strWhatever;
    Found, my Computer name.
    But how found another computer name, when I have IP.
    Some like that:

    Code:
    string strWhatever = Request.ServerVariables("LOGON_USER") = 123.123.123.123
    TextBox1.Text = strWhatever;
    How make, what this work.

    I hope, you get wath i need.
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Smurfas,

    When you request server variables you are getting information about the user that is logged on to the server. I'm guessing that you are using ASP.NET in which case you can use the following code to retrieve a computer name from the DNS when you know the IP address:
    Code:
     
    string sComp = System.Net.Dns.GetHostEntry("127.0.0.1").HostName;
    Hope this helps,

    Dr B

    PS Please post ASP.NET questions in the .NET Forum. The ASP Forum is for Classic ASP only.

    Comment

    • Smurfas
      New Member
      • Jul 2008
      • 30

      #3
      "PS Please post ASP.NET questions in the .NET Forum. The ASP Forum is for Classic ASP only." - Sorry


      String sComp = System.Net.Dns. GetHostEntry("1 27.0.0.2").Host Name;
      Label1.Text = sComp;

      But when i Put My friend IP adresas, then show only this: 127.0.0.2
      Don't see computer name.

      When I put my IP adress 127.0.0.1, i see My computer name:
      Dzimbo-B9646K9\Dzimbo

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Is your friend on your local network? The method above works by retrieving the machine name from the DNS not from the machine itself.

        Dr B

        Comment

        • Smurfas
          New Member
          • Jul 2008
          • 30

          #5
          Originally posted by DrBunchman
          Is your friend on your local network? The method above works by retrieving the machine name from the DNS not from the machine itself.

          Dr B
          Yes, hi in local network

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            The above method will probably only work if you have a DNS Server. Do you?

            Comment

            • Smurfas
              New Member
              • Jul 2008
              • 30

              #7
              I have parallel question.

              I use this, when i found Computer name:

              String IP = "127.0.0.1" ;
              String Vardas = System.Net.Dns. GetHostEntry(IP ).HostName;

              How in this function put My made-up IP Address?(I don't wont found IP automation) :

              string name = Page.User.Ident ity.Name;
              name = name.Substring( name.IndexOf(@" \") + 1);

              I hop understant my question.
              I wont like this:
              string name = Page.User.Ident ity(IP).Name; - but don't work. How make, what this work

              Comment

              • Smurfas
                New Member
                • Jul 2008
                • 30

                #8
                Nobody have Idias? :[

                Comment

                Working...