473,809 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test if host is online

I would like to find a simple way to test if a computer is online.

I found a lot of code on internet about using existing ping class...but the
code was not looking really good. There must be a simple way to do that?

Thanks!
Nov 17 '05 #1
4 8758
hi,

if you want to know if a host is accesible a ping MAY be helpful, it may
also be filtered out so you cannot really trust on it.

You could also try to connect to a known service that host provide, in this
case you have the drawback that the service may be down but the host still
up :)
It depends of your intentions about what is the best solution.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Marc-André" <Marc-André@discussio ns.microsoft.co m> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
I would like to find a simple way to test if a computer is online.

I found a lot of code on internet about using existing ping class...but
the
code was not looking really good. There must be a simple way to do that?

Thanks!

Nov 17 '05 #2
Well, I would like to go with a ping...but I have notice that c# doesn't
containt a easy way to do a ping. I have try to use a existing ping
application (http://www.dataidee.com/ping/ping.htm)

The problem is that you got to be a admin on the computer to use
"SocketType.Raw "

I can't belive theres nothing simple that let you know if a computer is
online...

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi,

if you want to know if a host is accesible a ping MAY be helpful, it may
also be filtered out so you cannot really trust on it.

You could also try to connect to a known service that host provide, in this
case you have the drawback that the service may be down but the host still
up :)
It depends of your intentions about what is the best solution.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Marc-André" <Marc-André@discussi ons.microsoft.c om> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
I would like to find a simple way to test if a computer is online.

I found a lot of code on internet about using existing ping class...but
the
code was not looking really good. There must be a simple way to do that?

Thanks!


Nov 17 '05 #3
Well, finally I have found something....

http://spaces.msn.com/members/dotnot...mt&_c=blogpart

private bool isMachineReacha ble(string hostName)

{

System.Net.IPHo stEntry host = System.Net.Dns. GetHostByName(h ostName);

string wqlTemplate = "SELECT StatusCode FROM Win32_PingStatu s WHERE Address
= '{0}'";

System.Manageme nt.ManagementOb jectSearcher query = new
ManagementObjec tSearcher();

query.Query = new ObjectQuery(Str ing.Format(wqlT emplate,
host.AddressLis t[0]));

query.Scope = new ManagementScope ("//localhost/root/cimv2");

ManagementObjec tCollection pings = query.Get();

foreach(Managem entObject ping in pings)
{

if( Convert.ToInt32 (ping.GetProper tyValue("Status Code")) == 0)
return true;
}

return false;
}

If I have a problem with it....I will give youi my feedback on it...

"Marc-André" wrote:
I would like to find a simple way to test if a computer is online.

I found a lot of code on internet about using existing ping class...but the
code was not looking really good. There must be a simple way to do that?

Thanks!

Nov 17 '05 #4
No need to get the IP address from the hostname using GetHostByName, the
address property takes a host name or an address.

SELECT StatusCode FROM Win32_PingStatu s WHERE Address='MyHost name'
Willy.

"Marc-André" <Ma******@discu ssions.microsof t.com> wrote in message
news:1E******** *************** ***********@mic rosoft.com...
Well, finally I have found something....

http://spaces.msn.com/members/dotnot...mt&_c=blogpart

private bool isMachineReacha ble(string hostName)

{

System.Net.IPHo stEntry host = System.Net.Dns. GetHostByName(h ostName);

string wqlTemplate = "SELECT StatusCode FROM Win32_PingStatu s WHERE
Address
= '{0}'";

System.Manageme nt.ManagementOb jectSearcher query = new
ManagementObjec tSearcher();

query.Query = new ObjectQuery(Str ing.Format(wqlT emplate,
host.AddressLis t[0]));

query.Scope = new ManagementScope ("//localhost/root/cimv2");

ManagementObjec tCollection pings = query.Get();

foreach(Managem entObject ping in pings)
{

if( Convert.ToInt32 (ping.GetProper tyValue("Status Code")) == 0)
return true;
}

return false;
}

If I have a problem with it....I will give youi my feedback on it...

"Marc-André" wrote:
I would like to find a simple way to test if a computer is online.

I found a lot of code on internet about using existing ping class...but
the
code was not looking really good. There must be a simple way to do that?

Thanks!

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2853
by: Atz | last post by:
Hi to all ! Im using MySql front and PHP 5 for some web shop. I didn't try it so far but i guess that the online data insertation ( accept costs and time ) should be the same process like for local connection. Problem: I have to create online ( on remote server ) some 6 tables and some 20 fields with MySql front. Ok. This shouldn't be great problem ( i hope :-)).
3
2252
by: Remon Huijts | last post by:
Hi, When I use php mail() in a script on my localhost to send an HTML message to an e-mailaccount on my online host, all is fine. When I use php mail() in a script on my online host to send an HTML message to some e-mailaccount other than on my online host, all is fine. But when I use php mail() in a script on my online host to send an HTML message to an e-mailaccount on that same online host, I receive the message code as plain text.
19
2443
by: Caesar | last post by:
Hi, I'm wondering if anyone here can point me in the right direction. My host does not provide php, and so I need to pull this data from another server that does support such scripting. Help? JC
0
882
by: James | last post by:
I have opened the ports I believe I require in order to play Links online. I can host a game, & then it plays perfectly. However, if I attempt to join a game, when the game loads I get the annoying 'Connection Failed' message. Any suggestions as to where I should be looking? OS is WinXP
1
2113
by: Nalaka | last post by:
Hi, I am testing with Visual studio 2005, web projects. Situation: I have one solution with two web projects, created as file system projects. (I am tesing using the built in server, not IIS) First project is a webService. Second consumes the webservices by the first.
6
7203
by: SevDer | last post by:
Is there a way to test guid string? I want to do it without try catch block to save on performance. Thanks in advance. -- SevDer
7
1733
by: GopherGold | last post by:
I have a site that uses a combination of Web.Sitemap and a SqlSiteMapProvider that I created (thanks to Jeff Proisse @ MSDN). One node of the Web.Sitemap is the same as the root node from the SqlSiteMap. Each SiteMapProvider sources a separate menu. I use this configuration because it allows me to control static display depth on the menus separately. This worked fine on my local development machine, but when I moved the site to a...
6
1518
by: malcolm | last post by:
Hi, I would like help to get started on an idea. I have prior knowledge of how to do this so please be gentle with me as I am a complete beginner when it comes to ASP. I have a website hosted by an internet host and want to add a PHPBB2 forum hosted on my own server. What I would like to introduce to my website is something like this
3
2191
by: tutusaint | last post by:
I have a user count script thats well on my local host. I uploaded it into my webserver and it always shows 1 user online and even when i login from diferent ip addresses. The codes of my script is below. Please help $server = "localhost"; $db_user = "root"; $db_pass = "root"; $database ="test"
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.