Bash

更改 MAC 地址後無法連接網際網路

  • March 1, 2018

我一直在製作一個 BAsh 腳本,將您的 MAC 地址更改為您從列表中選擇的任何製造商的地址。在執行的腳本的最後一部分,它在完成之前停止。這是該部分的程式碼:

function spoofUseMAC() {

 echo
 read -p "[*] $($stopAllFX; $bgBlack; $white)Enter the number code for manufacturer: >>> " num
 echo "[-] Generating MAC Address"
 num=$( expr $num - 1 )
 declare -a array
 while read -r; do
   array+=( "$REPLY" )
 done < addr.txt
 end=$( for i in {1..6} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
 macAddress=${array[$num]}$end
 echo "[-] MAC Address generated !"
 echo "[-] Using address: $macAddress"

 $skyBlue; $bold; echo
 ifconfig
 $white
 read -p "[*] $($stopAllFX; $bgBlack; $white)Select an interface: >>> " iface
 $yellow; echo "[-] $iface selected !"
 $white; echo  "[-] Disabling $iface ..."
 ifconfig $iface down
 ifconfig '$iface' hw ether '$macAddress'
 echo "[-] MAC Address spoofed !"
 sleep 1
 echo "[-] Enabling $iface ..."
 ifconfig '$iface' up
 echo "[-] $iface enabled !"
 echo "[-] Using address: $macAddress"
 exit

}

function spoofSearchAgainOrNot() {

 $bold; $white; echo
 echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
 $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search again"
 $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Use one of these"
 read -p ">>> " searchAgainOrNot
 if [[ "$searchAgainOrNot" == "0" ]]; then
   spoofSearch
 elif [[ "$searchAgainOrNot" == "1" ]]; then
   spoofUseMAC
 else
   spoofSearchAgainOrNot
 fi

}

# Spoof, search option selected
function spoofSearch() {

 $bold; echo
 read -p "[*] $($stopAllFX; $bgBlack; $white)Search for a manufacturer: >>> " search
 $blue; awk -F '#' '{printf("%10d %s\n", NR, ":" $1 )}' /usr/bin/oui.txt | grep -i $search

 spoofSearchAgainOrNot

}

# Spoof
function spoof() {

 echo; $white
 echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
 $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search for a manufacturer"
 $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Browse for a manufacturer through $($bold)long $($stopAllFX; $bgBlack; $white)list"
 read -p ">>> " searchOrBrowse
 if [[ $searchOrBrowse == "0" ]]; then
   spoofSearch
 elif [[ $searchOrBrowse == "1" ]]; then
   spoofBrowse
 else
   spoof
 fi

}

為什麼執行此腳本後我不能使用網際網路(git clone說)?could not resolve hostname: github.com為什麼它沒有完成?

編輯:這應該適用於 MacOS 和 Linux。在 MacOS 上,沒有ip route命令,但在 Linux 中,ip route結果是:

192.168.0.0/24 dev wlp1s0  proto kernel scope link  src 192.168.0.18 
192.168.0.0/24 dev wlp1s0  proto kernel scope link  src 192.168.0.18  metric 600

我發現了問題:其中一個$ifaces 在它不應該有引號時圍繞它。

有些卡對更改/欺騙 MAC 地址有點挑剔。

在 OSX 中,介面 MAC 地址的更改,特別是 wifi 介面,必須多次完成,直到正確,例如經常在一個循環中,因為它必須在一定時間內完成,我懷疑;首次使用最新版本的 OSX/MacOS 時通常不會假定它。

值得注意的是,在 OSX 中,介面/驅動程序似乎在 MAC 之後的幾秒鐘內感到困惑,但它們確實恢復了。

稀有品牌不會喜歡它,在某些品牌中,不建議您更改前 3 個八位字節(前 6 位數字,減去“:”),即製造商 ID。

通常你會失去你的預設路由,或者路由器/AP 可能會失去你是誰的概念;雖然該過程大部分應該是自動的,但在某些情況下,在 Linux 中,您可能必須在更改 MAC 地址後重新啟動 DHCP 服務。

引用自:https://unix.stackexchange.com/questions/366181