IP address search and arp -a command - terminal

I don't understand why I found two different IP address looking from System Preference and Terminal, here attached a screen.
And also when I search with "arp -a" command why there is that second one address (224.0.0.251) screenshot??
specchioritmico#Airdisporitmico ~ % arp -a
? (192.168.0.1) at 44:37:e6:4c:16:b7 on en3 ifscope [ethernet]
? (224.0.0.251) at 1:0:5e:0:0:fb on en3 ifscope permanent [ethernet]

Related

macOS set DNS server to default value

I'm building a tool to manage DNS in macOS.
I know how to set dns server in terminal.
networksetup -setdnsservers Wi-Fi 1.1.1.1
but I don't to know how to unset it, or set it to the default value
networksetup -setdnsservers Wi-Fi
seems not working.
Anyone help ?
Give a try to:
networksetup -setdnsservers Wi-Fi empty
Then check with:
scutil --dns
From man networksetup:
-setdnsservers networkservice dns1 [dns2] [...]
...
If you want to clear all DNS entries for the specified network service,
type "empty" in place of the DNS server names.

Mac OS terminal command How to differentiate wlan from ethernet address?

I'm making a mac os app. I'm trying to get the ethernet and wlan addresses. I know these are en0 and en1 addresses but depending on devices, en0 can be the ethernet or the wlan one. Is there a way to know which one it is?
So far I'm using this which gets me both addresses but don't differentiate them:
let task=Process.init()
task.launchPath="/sbin/ifconfig"
task.arguments=["en0"] //or en1
let pipe=Pipe()
task.standardOutput=pipe
task.launch()
let data=pipe.fileHandleForReading.readDataToEndOfFile()
guard let stringResult=String(data: data, encoding: String.Encoding.utf8) as NSString? else{wlanFailed();return}
print("en0:", stringResult)
EDIT
So now I'm trying to run this command networksetup -listnetworkserviceorder which works from my terminal.
But I don't know how to make it work from my Mac app. For example, with this:
let task=Process.init()
task.launchPath="/sbin/networksetup"
task.arguments=["-listnetworkserviceorder"]
I get:
launch path not accessible
These are some commands that help to match the interface with the hardware name:
networksetup -listallhardwareports
networksetup -listnetworkserviceorder
system_profiler SPNetworkDataType
scutil <<< "list" | grep -i airport
Thanks #artem-dorodovskiy and #nbari for giving me the command line.
I found how to write it thanks to this SOF answer.
let task=Process.init()
task.launchPath="/usr/bin/env"
task.arguments=["networksetup", "-listnetworkserviceorder"]

IP aliasing on en0 on macbook

I am trying to add multiple IP addresses to my en0 interface on my macbook with macOS sierra 10.13.3 version, but it is not working as expected.
sudo ifconfig en0 alias 10.0.0.1 255.255.255.255
sudo ifconfig en0 alias 10.0.0.2 255.255.255.255
sudo ifconfig en0 alias 10.0.0.3 255.255.255.255
After doing this, 10.0.0.1 resolves. I can ping.
But not 10.0.0.2 & 10.0.0.3.
Is this a known limitation or bug?
Any additional steps need to be done to make this work?
Probably a restriction?
I am able to circumvent this problem by using loopback interface.
sudo ifconfig lo0 alias 127.0.0.2 0xff000000
sudo ifconfig lo0 alias 127.0.0.3 0xff000000
and this enabled me to successfully setup port forwarding on same port across IPs on my machine.
But would be nice to know why it didn't work on en0.

BASH on OS X: Why does this script not work?

I wrote the following BASH script to change my MAC address back to the normal one after I am done using a spoofed MAC address:
sudo ifconfig en1 ether 00:11:22:33:44:55
It works. However, the following code doesn't work:
mac=$(cat /volumes/KYLE-OSX/mac.txt)
sudo ifconfig en1 ether $mac
I am given the following error message:
ifconfig: can't set link-level netmask or broadcast
I am unable to predict what the MAC address is going to be, so I need to be able to use any possible MAC address in the 'sudo ifconfig en1 ether' statement.
The fundamental problem was diagnosed in comments already -- the file contains more than just the MAC address. Here's a simple workaround for that.
mac=$(grep -Eo '\<[0-9a-f]{2}(:[0-9a-f]{2}){5}\>' /Volumes/KYLE-OSX/mac.txt)

Shell command for getting mac address in OS X

I have been handicapped by the GUI and always seem to ask of help when it comes to the command line.
On Mac OS X only I need a command line to get the mac address of the wifi currently in use.
Help!
ifconfig en1 gets the interface details for wifi, the mac is on a line starting with ether, and is the second word on that line so:
ifconfig en1 | awk '/ether/{print $2}'
I think the best and easiest way to get the information is using this command:
networksetup -listallhardwareports
It will return a nice list of devices like this:
Hardware Port: USB 10/100/1000 LAN
Device: en6
Ethernet Address: 00:e0:4c:...
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: 80:e6:50:...
Hardware Port: Bluetooth PAN
Device: en3
Ethernet Address: 80:e6:50:...
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: 72:00:05:...
Hardware Port: Thunderbolt 2
Device: en2
Ethernet Address: 72:00:05:...
Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: 72:00:05:...
VLAN Configurations
===================
networksetup -getmacaddress <interface>
Wifi mac address is normally can be found in en0. So you may try this command on Terminal
ifconfig en0 | awk '/ether/{print $2}'
ifconfig should do the trick, it'll display a bunch of info including your MAC address. Alternatively it'll be in your network settings under system preferences.
EDIT
On a computer with just a wireless connection, en0 will have your wifi settings. The tag labeled with ether will most likely be your MAC address.
If you have both a wired and wireless connection, it'll be under ether in the en1 tag
Source: http://m.iclarified.com/entry/index.php?enid=30929
This will easily give you the specific Mac Address for your Wifi Interface
networksetup -listallhardwareports | grep Wi-Fi -A 3 | awk '/Ethernet Address:/{print $3}'

Resources