Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Test for local host

Posted on 2013-05-31
Medium Priority
Last Modified: 2013-06-01
How can I detect if the local host is running?


if (local host)
      Do something
else  //remote host
      Do Nothing

Question by:Dovberman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 13

Expert Comment

by:Jitendra Patil
ID: 39212493
try the code given below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;

namespace ConsoleApplication2
    class Program
        static void Main(string[] args)
                Console.WriteLine("Local IP Address: " + GetIPAddress(Dns.GetHostName()));
                Console.WriteLine("Google IP:" + GetIPAddress("google.com"));

                if (GetIPAddress(Dns.GetHostName()).ToString() == "::1")
                    Console.WriteLine("This is local host address");
                    Console.WriteLine("This is website address");


        public static IPAddress GetIPAddress(string hostName)
            Ping ping = new Ping();
            var replay = ping.Send(hostName);

            if (replay.Status == IPStatus.Success)
                return replay.Address;
            return null;


Open in new window

hope this helps.
LVL 16

Accepted Solution

Rose Babu earned 1200 total points
ID: 39212545
Try this...
HttpContext context = HttpContext.Current;

if (context.Request.Url.ToString().StartsWith("http://localhost"))
	// running from Local Host

	// running from Remote Host


Open in new window


Author Comment

ID: 39212788
I used the suggestion from srosebabu.

Thanks to both of you.

Author Closing Comment

ID: 39212790
Thank you

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question