Skip to content

Instantly share code, notes, and snippets.

@saman-taghavi
Created September 22, 2023 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saman-taghavi/8fa8bc81e76fb47e31f7ff486fd61359 to your computer and use it in GitHub Desktop.
Save saman-taghavi/8fa8bc81e76fb47e31f7ff486fd61359 to your computer and use it in GitHub Desktop.
scriptKit set and reset dns for mac, set dns to shcean dns
// Name: change DNS mac
import "@johnlindquist/kit";
// Define the DNS servers you want to set
const dnsServer1 = "185.51.200.2";
const dnsServer2 = "178.22.122.100";
// Function to change DNS settings
async function changeDNS() {
try {
const currentDNSservers = await $`networksetup -getdnsservers Wi-Fi`;
if (currentDNSservers.stdout.includes(dnsServer1)) {
// reset the dns servers
await $`networksetup -setdnsservers Wi-Fi empty`;
notify("DNS settings reset!");
return;
}
// Generate the networksetup command
await $`networksetup -setdnsservers Wi-Fi ${dnsServer1} ${dnsServer2}`;
notify("DNS settings changed!");
} catch (error) {
console.error("Failed to change DNS settings:", error);
}
}
// Call the function to change DNS settings
changeDNS();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment