473,785 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking if the computer is online

Hi all,

I have a silly question. Is there are simple way to check if the computer
is connected to the Internet? It seems this should be a pretty
straight-forward thing to do, but as I am totally unfamiliar with sockets
and such, I ask for your help before getting my hands dirty.

Cheers,

Mickel G.

--
Mickel Grönroos, application specialist, linguistics, Research support,CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi

Jul 18 '05
14 4976
> On Thu, 18 Sep 2003, Thomas Bellman wrote:
Or perhaps you should tell us *why* you believe you need to check
if the computer is connected to the Internet or not. Then we can
go directly to telling you that it is a bad idea, and suggest what
you should do instead. <0.5 wink>

*I* would like to use it to run a service in the background on my
Windows machine checking the machines ip adress perhaps once an hour,
and if it was different than it is supposed to be, it should send an
email to my mail adress containing the time and the ip adress.

That should make it possible to make a stolen computer "phone home" with
enough data to track it down.

But if it tries to call up on a modem, it has sort of given itself up.
An the new "owner" might get suspicious.
regards Max M
Jul 18 '05 #11
Have you tried :
socket.gethostb yname(socket.ge thostname())
or
socket.gethostb yname_ex(socket .getfqdn())[2]

Normally the result should be different if you're connected or not

Cheers,
Pierre

"Mickel Grönroos" <mi****@csc.f i> a écrit dans le message de
news:ma******** *************** **********@pyth on.org...
On Thu, 18 Sep 2003, Thomas Bellman wrote:
Mickel Grönroos <mi****@csc.f i> wrote:
Hi all,
I have a silly question. Is there are simple way to check if the computer is connected to the Internet? It seems this should be a pretty
straight-forward thing to do, but as I am totally unfamiliar with sockets and such, I ask for your help before getting my hands dirty.


First of all you need to define what "being online" means...

[...] Or perhaps you should tell us *why* you believe you need to check
if the computer is connected to the Internet or not. Then we can
go directly to telling you that it is a bad idea, and suggest what
you should do instead. <0.5 wink>


OK, here's what I want to do:

When the Tkinter application I am writing starts up, it checks if certain
files on the web exists and if so, it downloads them to a local directory
replacing possible earlier copies of these files. So, what I mean by
checking if the computer is online is that I want to check if I can access
these certain remote files with urllib.urlretri eve(). If I can, then I
download them. If I can't, I assume the computer is not connected to the
Internet and I skip the update phase.

The problem with just running urllib.urlretri eve() is that the execution
of the script halts as there is no timeout available for Python 2.2.2. (I
tried timeoutsocket.p y to get this done, but that only worked on Windows
2000, not Redhat Linux 7.0. I also tried upgrading to Python 2.3, but that
caused some other problems, especially with the gettext module and with
the fact that my ISO-8859-1 encoded files needed a "coding" line.)

So that's that. Anybody still got a few lines of code that would get this
done on Python 2.2.2 on Windows _and_ Linux?

Cheers,

/Mickel G.

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi
Jul 18 '05 #12
Have you tried :
socket.gethostb yname(socket.ge thostname())
or
socket.gethostb yname_ex(socket .getfqdn())[2]

Normally the result should be different if you're connected or not

Cheers,
Pierre

"Mickel Grönroos" <mi****@csc.f i> a écrit dans le message de
news:ma******** *************** **********@pyth on.org...
On Thu, 18 Sep 2003, Thomas Bellman wrote:
Mickel Grönroos <mi****@csc.f i> wrote:
Hi all,
I have a silly question. Is there are simple way to check if the computer is connected to the Internet? It seems this should be a pretty
straight-forward thing to do, but as I am totally unfamiliar with sockets and such, I ask for your help before getting my hands dirty.


First of all you need to define what "being online" means...

[...] Or perhaps you should tell us *why* you believe you need to check
if the computer is connected to the Internet or not. Then we can
go directly to telling you that it is a bad idea, and suggest what
you should do instead. <0.5 wink>


OK, here's what I want to do:

When the Tkinter application I am writing starts up, it checks if certain
files on the web exists and if so, it downloads them to a local directory
replacing possible earlier copies of these files. So, what I mean by
checking if the computer is online is that I want to check if I can access
these certain remote files with urllib.urlretri eve(). If I can, then I
download them. If I can't, I assume the computer is not connected to the
Internet and I skip the update phase.

The problem with just running urllib.urlretri eve() is that the execution
of the script halts as there is no timeout available for Python 2.2.2. (I
tried timeoutsocket.p y to get this done, but that only worked on Windows
2000, not Redhat Linux 7.0. I also tried upgrading to Python 2.3, but that
caused some other problems, especially with the gettext module and with
the fact that my ISO-8859-1 encoded files needed a "coding" line.)

So that's that. Anybody still got a few lines of code that would get this
done on Python 2.2.2 on Windows _and_ Linux?

Cheers,

/Mickel G.

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi
Jul 18 '05 #13
On Wed, 24 Sep 2003, Pierre Quentel wrote:
Have you tried :
socket.gethostb yname(socket.ge thostname())
or
socket.gethostb yname_ex(socket .getfqdn())[2]

Normally the result should be different if you're connected or not


Thanks for the tip! I tried this and the second line freezes execution
when I have unplugged my Ethernet cable. So again, I need a timeout on my
socket. This is not available in Python 2.2.2. I reckon I need to try
Python 2.3.

/Mickel G

Jul 18 '05 #14
On Wed, 24 Sep 2003, Pierre Quentel wrote:
Have you tried :
socket.gethostb yname(socket.ge thostname())
or
socket.gethostb yname_ex(socket .getfqdn())[2]

Normally the result should be different if you're connected or not


Thanks for the tip! I tried this and the second line freezes execution
when I have unplugged my Ethernet cable. So again, I need a timeout on my
socket. This is not available in Python 2.2.2. I reckon I need to try
Python 2.3.

/Mickel G

Jul 18 '05 #15

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

Similar topics

10
3692
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
2
4341
by: Daniel Orner | last post by:
Is it at all possible to use JavaScript to find out if someone's online or not? E.g. to try and fetch a URL and figure out if it failed or not? I'm trying to add some functionality to my primarily online program to also work offline, but I'd need this sort of thing to make it work well. Thanks!
3
1159
by: RS | last post by:
Is there a function that will tell you if your computer is online to the internet ?
1
950
by: alex | last post by:
Hi May i know how to do a check to find out how many users are online and logged on to our system? Btw, i am using vb.net. Perhaps show me some articles on this issue? regards Alex
7
3292
by: giddy | last post by:
hi, i'm making a netowork based app. and if i have the UNC path to a local computer is there a way i can check whether the pc is online/offline?? Gideon
6
2688
by: MattPKaiser | last post by:
I am trying to find a way to check if a computer on a network is "online" so that I can access a file on a share. In short I maintain a list of computers that have my service running (in the client application) and in my client program I allow the user to change the computer that they are accessing. If a computer that is on the list becomes unplugged and I try to access a file with a FileStream the filestream creation takes 8-10...
125
6619
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this problem. http://www.jilp.org/vol9/v9paper10.pdf Specifically, they measured the overhead of a bounds
25
2845
by: doznot | last post by:
Let's say you want to use Moodle to teach an introductory class in PHP programming. Some of the students have little or no computer experience. In addition to background reading and topics-oriented assignments supplied by Moodle, you want to build an online text editor into the course, so students can type their PHP programs and HTML directly into files on the server, so they don't have to fight with NotePad on Windows PCs in a lab, and...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
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...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6744
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
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
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
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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.