You are not logged in.

#1 2010-12-29 16:12:50

RedScare
Member
Registered: 2009-03-28
Posts: 91

Writing a daemon to check if system is online

Hello. I've never written a daemon before, but I'm pretty comfortable with C/C++, and I wanted to write a daemon that would react when my system lost or gained internet access. Does anyone have any ideas as to how to start?

I know this is basically a terrible question, but perhaps someone could point me to events or signals that I could use to get started? Or perhaps another program that does something similar? Thanks a lot for any help.

Offline

#2 2010-12-29 16:29:49

MadTux
Member
Registered: 2009-09-20
Posts: 553

Re: Writing a daemon to check if system is online

What about a ping to a web site, for example opendns.org?

ping -c 4 www.opendns.org

This would send 4 ping messages to the server.

Offline

#3 2010-12-30 04:25:21

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Writing a daemon to check if system is online

Thanks for the idea, but that's gonna have to happen on a per-program basis and is pretty slow/heavy on the network. What I want is something like the network daemon/notification thingy in Windows, where there are constant, instantaenous updates on network connectivity. If it can be done in Windows I think it could be done in Linux:)

Offline

#4 2010-12-30 05:33:07

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Writing a daemon to check if system is online

Well first, you need to define what you consider "internet access"? Then you can start thinking about how to monitor that.

Under which circumstances are you "connected"?
- Anytime the NIC has a link to a switch/modem/other and is "up"
- Anytime you can reach something in your ISP's network? (What if they have routing issues and you can't get anywhere else?)
- Anytime you can reach a specific local website? (What if that website goes down?)
- Anytime you can reach a specific overseas website? (What is there are international routing problems, but you still have national routing?)

The best compromise to determine "online" state is to ping my ISP's DNS server which is an ANYCAST address.

Offline

#5 2010-12-30 05:38:49

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Writing a daemon to check if system is online

I use this - it's simple, but does exactly what I need...

$(host google.com>/dev/null && echo $GRN"ON" || echo $RED"NO")

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#6 2010-12-31 13:40:38

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: Writing a daemon to check if system is online

I think NetworkManager (& associated GUI tools) does what you want, it gives you features quite similar to the little systray network thingie you find in Windows. I use it in KDE and it gives me no problems. Wiki link. I can't tell if you're just interested in writing something like this for educational purposes though, if that's the case then maybe this article will help you.

Offline

#7 2010-12-31 15:26:11

RedScare
Member
Registered: 2009-03-28
Posts: 91

Re: Writing a daemon to check if system is online

@Bralkein: Yeah, I sorta wanted to write a lightweight version of that/learn about this stuff. Thanks for the link, but unfortunately it only tells me the structure of a daemon, not the hardware/software interface I was looking for, or the information about sleeping. Thank you though.

@jasonwryan: I have one of those too, but I have to run it manually, it doesn't automatically run on a connect/disconnect/other network event.

@fukawi2: I agree with your qualification for 'online', now I just need an efficient way to check that state.

Thanks to everyone for their answers.

Last edited by RedScare (2010-12-31 15:26:23)

Offline

#8 2011-01-13 21:28:01

ks1
Member
From: Atlanta, Georgia
Registered: 2006-03-26
Posts: 62
Website

Re: Writing a daemon to check if system is online

RedScare: Why not look at the source code for NetworkManager?

Offline

Board footer

Powered by FluxBB