{"id":21989033,"url":"https://github.com/imweb/lan-settings","last_synced_at":"2025-07-31T11:06:46.264Z","repository":{"id":76789581,"uuid":"109727116","full_name":"imweb/lan-settings","owner":"imweb","description":"LAN Settings 设置操作系统局域网配置","archived":false,"fork":false,"pushed_at":"2023-05-08T15:13:34.000Z","size":213,"stargazers_count":24,"open_issues_count":1,"forks_count":7,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-14T15:57:36.249Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-06T17:26:20.000Z","updated_at":"2024-02-04T03:07:53.000Z","dependencies_parsed_at":"2023-07-06T14:00:47.369Z","dependency_job_id":null,"html_url":"https://github.com/imweb/lan-settings","commit_stats":{"total_commits":35,"total_committers":3,"mean_commits":"11.666666666666666","dds":"0.34285714285714286","last_synced_commit":"f47969c02a8a00f70f500fd1c7f455e5c3fd65da"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Flan-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Flan-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Flan-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Flan-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imweb","download_url":"https://codeload.github.com/imweb/lan-settings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251690414,"owners_count":21628106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T19:27:26.147Z","updated_at":"2025-04-30T11:28:24.648Z","avatar_url":"https://github.com/imweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lan-settings\n用于设置操作系统的局域网设置的Node模块（Node \u003e= v7.6）, 支持 Windows、macOS, 后续会支持 Linux\n\n![LAN Settings](https://raw.githubusercontent.com/imweb/lan-settings/master/assets/settings.png)\n\n\n## 安装\n`npm i --save lan-settings`\n\n\n## 使用 (Promise/Async)\n```js\nconst lan = require('lan-settings');\n\n\n// 获取设备的所有可用 NetworkServices (macOS Only)\nlan.listNetworkServices()\n  .then(console.log.bind(console, '获取成功: '))\n  .catch(console.log.bind(console, '获取失败: '));\n\n\n// 获取当前局域网设置信息，如果err非空，表示获取失败\nlan.getSettings()\n  .then(console.log.bind(console, '获取成功: '))\n  .catch(console.log.bind(console, '获取失败: '));\n  // output:\n  // { autoDetect: false,\n  //   autoConfig: false,\n  //   autoConfigUrl: '',\n  //   proxyEnable: true,\n  //   proxyServer: '127.0.0.1:8888',\n  //   bypassLocal: false,\n  //   bypass: '' }\n\n\n// 自动检测设置\nlan.setSettings({\n  autoDetect: true\n})\n  .then(console.log.bind(console, '设置成功'))\n  .catch(console.log.bind(console, '设置失败: '));\n\n\n// 开启并这种PAC脚本\nlan.setSettings({\n  autoConfig: true,\n  autoConfigUrl: 'http://127.0.0.1:50011'\n})\n  .then(console.log.bind(console, '设置成功'))\n  .catch(console.log.bind(console, '设置失败: '));\n\n\n// 开启并设置统一的代理服务器，开启本地代理白名单\nlan.setSettings({\n  proxyEnable: true,\n  proxyServer: '127.0.0.1:8888',\n  bypassLocal: true\n})\n  .then(console.log.bind(console, '设置成功'))\n  .catch(console.log.bind(console, '设置失败: '));\n\n\n// 高级设置，对http、https、ftp、socks分别设置不同的代理，并设置白名单域名前缀\nlan.setSettings({\n  proxyEnable: true,\n  proxyServer: 'http=127.0.0.1:8888;https=127.0.0.1:8889;ftp=127.0.0.1:8890;socks=127.0.0.1:8891',\n  bypassLocal: false,\n  bypass: 'www.test;www.abc'\n})\n  .then(console.log.bind(console, '设置成功'))\n  .catch(console.log.bind(console, '设置失败: '));\n  \n  \n// 重置到修改前的设置\nlan.reset()\n  .then(console.log.bind(console, '设置成功'))\n  .catch(console.log.bind(console, '设置失败: '));\n```\n\n\n## 使用 (Callback)\n```js\nconst lan = require('lan-settings');\n// 获取设备的所有可用 NetworkServices (macOS Only)\nlan.listNetworkServices(function(err, services) {\n  console.log(err ? '获取失败' : '获取成功');\n  console.log(services);\n});\n\n// 获取当前局域网设置信息，如果err非空，表示获取失败\nlan.getSettings(function(err, settings) {\n  console.log(settings);\n    // output:\n    // { autoDetect: false,\n    //   autoConfig: false,\n    //   autoConfigUrl: '',\n    //   proxyEnable: true,\n    //   proxyServer: '127.0.0.1:8888',\n    //   bypassLocal: false,\n    //   bypass: '' }\n});\n\n// 自动检测设置\nlan.setSettings({ autoDetect: true }, function(err) {\n  console.log(err ? 'Fail' : 'Success');\n});\n\n// 开启并这种PAC脚本\nlan.setSettings({\n  autoConfig: true,\n  autoConfigUrl: 'http://127.0.0.1:30001/'\n}, function(err) {\n  console.log(err ? 'Fail' : 'Success');\n});\n\n// 开启并设置统一的代理服务器，开启本地代理白名单\nlan.setSettings({\n  proxyEnable: true,\n  proxyServer: '127.0.0.1:8888',\n  bypassLocal: true\n}, function(err) {\n  console.log(err ? 'Fail' : 'Success');\n});\n\n// 高级设置，对http、https、ftp、socks分别设置不同的代理，并设置白名单域名前缀\nlan.setSettings({\n  proxyEnable: true,\n  proxyServer: 'http=127.0.0.1:8888;https=127.0.0.1:8889;ftp=127.0.0.1:8890;socks=127.0.0.1:8891',\n  bypassLocal: false,\n  bypass: 'www.test;www.abc'\n}, function(err) {\n  console.log(err ? 'Fail' : 'Success');\n});\n\n// 重置到修改前的设置\nlan.reset(function(err) {\n  console.log(err ? 'Fail' : 'Success');\n});\n```\n\t\n\t\n\n## API\n\n### 注: networkservice 参数只适用于 macOS, 默认值为 \"All\", 即全部设置\n\n**lan.listNetworkServices([cb])**:    \n获取设备的所有可用 NetworkServices   \n`cb(err)` 为可选回调函数，如果重置失败，则err不为空; (macOS only)    \n若不传入回调函数, 则返回 Promise 对象;   \n\n```js\n[ 'iPhone USB', 'Ethernet', 'Wi-Fi', 'Bluetooth PAN', 'Thunderbolt Bridge' ]\n```\n\n\n**lan.getSettings([cb, networkservice])**:    \n获取当前局域网设置信息   \n其中 `cb(err, settings)` 为可选回调函数，如果出错err不为空，否则settings为当前系统局域网设置信息;   \n若不传入回调函数, 则返回 Promise 对象;\n\n```js\n{\n  autoDetect: true, // 是否开启自动检查设置\n  autoConfig: true, // 是否开启pac脚本 \n  autoConfigUrl: 'http://127.0.0.1:50011', // pac脚本的url\n  proxyEnable: true, // 是否开启代理设置\n  proxyServer: '127.0.0.1:8888', // 代理服务器ip和端口，如果使用高级设置，可能返回 `htt=127.0.0.1:8888;https=127.0.0.2:8889`等\n  bypassLocal: true, // 是否启用对本地地址不使用代理\n  bypass: 'www.test;www.abc' // 高级设置里面的白名单信息\n}\n```\n\n\n**lan.setSettings(settings, [cb, networkservice])**:    \n设置局域网信息   \nsettings如上，如果为null表示清空并关闭所有局域网设置项，`cb(err)` 为可选回调函数，如果设置失败，则err不为空。   \n若不传入回调函数, 则返回 Promise 对象;   \n\n\n**lan.reset(cb[, networkservice])**:    \n将局域网设置重置到修改前    \n`cb(err)` 为可选回调函数，如果重置失败，则err不为空。   \n若不传入回调函数, 则返回 Promise 对象;   \n\n\n# License\n[MIT](https://github.com/imweb/lan-settings/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimweb%2Flan-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimweb%2Flan-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimweb%2Flan-settings/lists"}