Giter Site home page Giter Site logo

airport_events's Introduction

AirportEvents

A MacOS specific Ruby library that receives WiFi related events from the system.

Currently supported events
Event Parameters Triggers when
connected String ssid, DateTime date A WiFi network has been successfully connected
disconnected DateTime date Computer is going to sleep, airport has been disabled or system halts

The library has only been tested on MacOS 10.7.5.

It was created to log the amount of time I spend on different WiFi networks. Check out the airport-log utility below for an example implementation.

Why?

  • Detect when a machine has joined a specific network.
  • Log the amount of time that's spent on different networks.

Installation

gem install airport_events

The gem depends on an official Apple command line tool called "airport" which is disabled by default. To enable the "airport" command, symlink it into PATH by running the following command:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

Example Usage

require 'airport_events'

# Create a new Watcher instance and set up some event listeners.
watcher = AirportEvents::Watcher.new

watcher.on :connected do |ssid, date|
  puts "Connected to #{ssid} on #{date}"
end

watcher.on :disconnected do |date|
  puts "Disconnected on #{date}"
end

# Start the watcher, which runs in a separate Thread.
watcher.start

# Keep program alive until interrupted (For instance: CTRL + C).
interrupted = false
trap("INT") { interrupted = true }

while true do
  exit if interrupted
  sleep 0.1
end

airport-log

The gem is shipped with a command called 'airport-log' which logs wifi connect/disconnect events to a JSON file.

For usage instructions run: airport-log -h

Example JSON output:

[
  {
    "ssid": "orca",
    "connected_at": "2013-02-24T22:35:54+00:00",
    "disconnected_at": "2013-02-24T22:47:38-05:00"
  },
  {
    "ssid": "beluga",
    "connected_at": "2013-02-24T22:48:23-05:00",
    "disconnected_at": null
  }
]

Note: When disconnected_at is null it means the network is still connected or a disconnect event was never sent.

airport_events's People

Contributors

jpettersson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

montana

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.