Skip to content

Instantly share code, notes, and snippets.

@davquipe
Last active April 4, 2023 15:12
Show Gist options
  • Save davquipe/9f405411426e44564caa14bea5ba173d to your computer and use it in GitHub Desktop.
Save davquipe/9f405411426e44564caa14bea5ba173d to your computer and use it in GitHub Desktop.
get-mac.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMG/WAznCnfT0Iy1Tp7uTPk",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/davquipe/9f405411426e44564caa14bea5ba173d/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "LMpLUDBOoci9"
},
"outputs": [],
"source": [
"import uuid"
]
},
{
"cell_type": "code",
"source": [
"direccion_mac = hex(uuid.getnode())[2:]\n",
"direccion_mac = ':'.join([direccion_mac[i:i+2] for i in range(0,11,2)])"
],
"metadata": {
"id": "XsFVt6imof6X"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(\"La direccion MAC es:\", direccion_mac)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "sS_sB7Exoij0",
"outputId": "4143ddea-fc14-4a2e-eab4-a153dd2ceccc"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"La direccion MAC es: 24:2a:c1:c0:00:c\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import uuid\n",
"\n",
"# Obtener la dirección MAC de la tarjeta de red\n",
"direccion_mac = hex(uuid.getnode())[2:]\n",
"direccion_mac = direccion_mac.upper().zfill(12)\n",
"\n",
"direccion_mac_sin_dos_puntos = ''.join([direccion_mac[i:i+2] for i in range(0, 12, 2)])\n",
"\n",
"print(\"La direccion MAC es:\", direccion_mac_sin_dos_puntos)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JLqmrG_Zok03",
"outputId": "fa224490-02d3-49a2-db26-0691e5bf51f2"
},
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"La direccion MAC es: 0242AC1C000C\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "b0Jd82cbo5bX"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment