Socket
Socket
Sign inDemoInstall

osx-wifi-cli

Package Overview
Dependencies
2
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

.eslintrc

70

osx-wifi-cli.js

@@ -8,3 +8,2 @@ #!/usr/bin/env node

var exec = require('child_process').exec
var commands = require('./commands.js')
var version = require('./package.json').version

@@ -22,2 +21,12 @@

var commands = {
osx: {
on: 'networksetup -setairportpower en0 on',
off: 'networksetup -setairportpower en0 off',
scan: '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan',
connect: 'networksetup -setairportnetwork en0 "NETWORK_TOKEN" "PASSWORD_TOKEN"',
currentNetwork: '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep -e "\\bSSID:" | sed -e "s/^.*SSID: //"'
}
}
var utils = commands.osx // If implementing other OSs, this is the place to check which we're on.

@@ -30,39 +39,32 @@

Object.keys(utils).forEach(function(key) {
if (typeof utils[key] == 'string') utils[key] = utils[key].replace('en0', cli.device)
if (typeof utils[key] === 'string') {
utils[key] = utils[key].replace('en0', cli.device)
}
})
args.splice(args.indexOf('--device'),2)
args.splice(args.indexOf('--device'), 2)
}
if (args[0] == 'on') execute(utils.on) //cli.on is a function
else if (cli.off) execute(utils.off)
else if (cli.restart) execute(utils.off).then(execute.bind(this,utils.on))
else if (cli.scan) execute(utils.scan).then(utils.parseScan).then(printNetworks)
else if (args.length == 2) execute(utils.connect.replace('NETWORK_TOKEN',args[0]).replace('PASSWORD_TOKEN',args[1]))
else if (args.length == 0) execute(utils.currentNetwork).then(utils.extractCurrentNetwork).then(help)
else cli.help()
if (args[0] === 'on') {
execute(utils.on) //cli.on is a function
} else if (cli.off) {
execute(utils.off)
} else if (cli.restart) {
execute(utils.off).then(execute.bind(this, utils.on))
} else if (cli.scan) {
execute(utils.scan).then(console.log.bind(console))
} else if (args.length === 2) {
execute(utils.connect.replace('NETWORK_TOKEN', args[0]).replace('PASSWORD_TOKEN', args[1]))
} else if (args.length === 0) {
execute(utils.currentNetwork).then(help)
} else {
cli.help()
}
////////////////////////////////////////////////
function help(currentNetwork) {
if (currentNetwork.SSID) {
console.log('you are connected to ' + currentNetwork.SSID)
} else {
console.log('you are not connected anywhere')
}
function help(SSID) {
console.log(SSID.trim() ? 'you are connected to ' + SSID : 'you are not connected anywhere')
//TODO: add more help text
}
function printNetworks(networksObj) {
networksObj.sort(function(a,b){return a.SSID > b.SSID})
var maxLengths = networksObj.reduce(function(lengths, network) {
Object.keys(network).forEach(function(key) {
lengths[key] = Math.max(lengths[key] || 0, network[key].toString().length)
})
return lengths
}, {})
//TODO: add numeric IDs and colors
var output = networksObj.map(function(network) { return Object.keys(network).map(function(key) {return pad(network[key].toString(), maxLengths[key]+2, ' ') }).join(' ')}).join('\n')
console.log(output)
}
function execute(cmd) {

@@ -72,5 +74,9 @@ //console.log('executing command:', cmd)

exec(cmd, function(err, strout, strerr) {
if (err) deferred.reject(new Error(err))
else if (strerr) deferred.reject(new Error(strerr))
else deferred.resolve(strout)
if (err) {
deferred.reject(new Error(err))
} else if (strerr) {
deferred.reject(new Error(strerr))
} else {
deferred.resolve(strout)
}
})

@@ -77,0 +83,0 @@ return deferred.promise

{
"name": "osx-wifi-cli",
"version": "1.0.0",
"version": "1.0.1",
"description": "A command line tool for managing wifi connection in osx",
"keywords": ["osx", "wifi", "cli", "mac", "wireless", "network"],
"keywords": [
"osx",
"wifi",
"cli",
"mac",
"wireless",
"network"
],
"homepage": "https://github.com/danyshaanan/osx-wifi-cli",

@@ -12,4 +19,7 @@ "author": {

},
"os": ["darwin"],
"os": [
"darwin"
],
"contributors": [],
"license": "MIT",
"licenses": [

@@ -26,11 +36,12 @@ {

"bugs": {
"url" : "https://github.com/danyshaanan/osx-wifi-cli",
"email" : "danyshaanan@gmail.com"
"url": "https://github.com/danyshaanan/osx-wifi-cli",
"email": "danyshaanan@gmail.com"
},
"preferGlobal": true,
"scripts": {
"start": "node ."
"start": "node .",
"test": "grunt"
},
"bin": {
"osx-wifi-cli" : "./osx-wifi-cli.js"
"osx-wifi-cli": "./osx-wifi-cli.js"
},

@@ -40,3 +51,8 @@ "dependencies": {

"commander": "2.1.0"
},
"devDependencies": {
"grunt": "0.4.5",
"grunt-bump": "0.0.16",
"grunt-eslint": "4.0.0"
}
}

@@ -1,2 +0,7 @@

## osx-wifi-cli - WIP
## osx-wifi-cli
[![Build Status](https://travis-ci.org/danyshaanan/osx-wifi-cli.png)](https://travis-ci.org/danyshaanan/osx-wifi-cli)
[![NPM Version](https://img.shields.io/npm/v/osx-wifi-cli.svg?style=flat)](https://npmjs.org/package/osx-wifi-cli)
[![License](http://img.shields.io/npm/l/osx-wifi-cli.svg?style=flat)](LICENSE)
### A command line tool for managing wifi connections on OSX

@@ -26,2 +31,1 @@

* To connect to network without a password (bad idea!) use `osx-wifi-cli networkname " "`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc