Skip to content

Instantly share code, notes, and snippets.

@Geczy
Last active December 30, 2023 05:48
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 Geczy/a7a3fc87daf7d9d8f5d98ee3d4c967ef to your computer and use it in GitHub Desktop.
Save Geczy/a7a3fc87daf7d9d8f5d98ee3d4c967ef to your computer and use it in GitHub Desktop.
free american airlines wifi

This Bash script automates the process of changing the MAC address on a network interface (specifically en0 on macOS, typically used for Wi-Fi) and attempts to activate a 20-minute Wi-Fi session, probably on an American Airlines flight. Here's a detailed breakdown:

  1. Root Check:

    • Exits if not run as root to ensure necessary permissions.
  2. Dependency Check:

    • Checks for the jq command, used for parsing JSON data.
  3. MAC Address Manipulation:

    • Defines generate_valid_mac function for new MAC addresses.
    • Resets Wi-Fi connection by turning it off and on.
    • Tries new MAC addresses until successful.
  4. Network Reconnection:

    • Waits until the en0 network interface is active again after MAC address change.
  5. Device ID Retrieval:

    • Makes an HTTP request to aainflight.com for a device_id, using current timestamp and a specific user agent.
  6. Offer Activation:

    • Retrieves device info and an offer ID from sponsoredaccess.viasat.com.
    • Attempts to activate a Wi-Fi offer using the device_id and offer_id.
  7. Status Check and Response:

    • Checks activation status.
    • Prints a success message with active Wi-Fi session time, or a failure message if activation fails.

This script is likely for use on American Airlines flights to automate free Wi-Fi access by spoofing MAC addresses and interacting with the in-flight Wi-Fi service's API. However, its usage might violate Wi-Fi provider terms of service and could be unethical or illegal.

#!/bin/bash
# If not running via sudo, exit
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
# quit if jq is not installed
if ! command -v jq &>/dev/null; then
echo "jq could not be found, install using brew install jq"
exit
fi
# Function to generate a valid MAC address
generate_valid_mac() {
echo $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
}
# Display current MAC and IP
current_mac=$(ifconfig en0 | awk '/ether/{print $2}')
echo "Current MAC address: $current_mac"
networksetup -setairportpower en0 off && sleep 0.5
networksetup -setairportpower en0 on && sleep 0.5
# Wait until we are disconnected from the network
printf "Disconnecting from network..."
while ifconfig en0 | grep -q "status: active"; do
printf "."
sleep 1
done
echo ""
# Keep trying new MAC addresses until successful
while true; do
new_mac=$(generate_valid_mac)
if ifconfig en0 ether "$new_mac" >/dev/null 2>&1; then
echo "MAC address rolled successfully"
break
fi
sleep 0.2
done
# Check if new mac is different from old mac, exit if not
if [ "$current_mac" = "$(ifconfig en0 | awk '/ether/{print $2}')" ]; then
echo "Failed. New MAC address is the same as the old MAC address? This should never happen."
exit
fi
networksetup -detectnewhardware &>/dev/null
networksetup -addpreferredwirelessnetworkatindex en0 aainflight.com 0 OPEN &>/dev/null
# Display new MAC and IP
echo "New MAC address: $(ifconfig en0 | awk '/ether/{print $2}')"
# while loop to wait until we have conection
printf "Connecting to network..."
while ! ifconfig en0 | grep -q "status: active"; do
printf "."
sleep 1
done
echo ""
TIMESTAMP=$(date +%s)
DEVICE_ID=""
AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
printf "Waiting to be assigned a device from AA..."
while [ -z "$DEVICE_ID" ]; do
printf "."
DEVICE_ID=$(curl -s "https://aainflight.com/device?random=$TIMESTAMP" \
-H 'accept: application/json' \
-H 'cache-control: no-cache' \
-H 'referer: https://aainflight.com/' \
-H "user-agent: $AGENT" \
--compressed | jq .guid -r)
sleep 1
done
echo ""
PRIMARY_DOMAIN="sponsoredaccess.viasat.com"
DEVICE_INFO=$(curl -s "https://$PRIMARY_DOMAIN/engage-advertising-service/api/v1/device" \
-H 'cookie: aal-termsAcceptance=1703259881243;' \
-H "deviceid: $DEVICE_ID" \
-H "referer: https://$PRIMARY_DOMAIN/americanairlines/" \
-H "user-agent: $AGENT" \
-H 'venuecode: aal' \
--compressed)
OFFER_ID=$(curl -s "https://$PRIMARY_DOMAIN/engage-advertising-service/api/v1/offers" \
-H 'content-type: application/json' \
-H 'cookie: aal-termsAcceptance=1703259881243;' \
-H "deviceid: $DEVICE_ID" \
-H "origin: https://$PRIMARY_DOMAIN" \
-H "referer: https://$PRIMARY_DOMAIN/americanairlines/" \
-H "user-agent: $AGENT" \
-H 'venuecode: aal' \
--data-raw '{"placements":[{"divName":"items","count":5,"siteName":"aal_connect","eventIds":[40,900],"adTypes":[18]}]}' \
--compressed | jq ".decisions.items[0].offerInteractionId" -r)
ACTIVATE_RESPONSE=$(curl -s "https://$PRIMARY_DOMAIN/engage-advertising-service/api/v1/offers/$OFFER_ID/activate" \
-X 'POST' \
-H 'content-type: application/json' \
-H 'cookie: aal-termsAcceptance=1703259881243;' \
-H "deviceid: $DEVICE_ID" \
-H "origin: https://$PRIMARY_DOMAIN" \
-H "referer: https://$PRIMARY_DOMAIN/americanairlines/" \
-H "user-agent: $AGENT" \
-H 'venuecode: aal' \
--compressed)
status_value=$(echo "$ACTIVATE_RESPONSE" | jq -r '.status')
if [ "$status_value" = "SUCCESS" ]; then
future_time=$(date -v+19M '+%I:%M:%S %p')
current_time=$(date '+%I:%M:%S %p')
echo "Successfully activated at $current_time"
echo "Keep this window open, this script will automatically run again in 19 minutes at $future_time..."
sleep 1140 # 19 minutes in seconds
bash "$0"
else
echo "Activation failed."
echo "$ACTIVATE_RESPONSE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment