Python では、uuid.getnode() を使用して MAC アドレスを生成し、format() および re() を使用して MAC アドレスの出力形式を設定できます。 Python の MAC アドレス取得方法を詳しく見ていきますので、ご参考になれば幸いです。
MAC アドレスとは何ですか?
ハードウェア アドレスとも呼ばれる MAC アドレスは常に一意であるため、ローカル ネットワーク上に同じ MAC アドレスを持つ 2 つのデバイスは存在しません。
MAC アドレスの主な目的は、ローカル エリア ネットワーク (LAN) またはその他のネットワーク上の各ノードに一意のハードウェア アドレスまたは物理アドレスを提供することです。ノードは、コンピュータまたはその他のデバイス (プリンタやルーターなど) がネットワークに接続されたままになるポイントを表します。
MAC アドレスを生成する方法
方法 1. uuid.getnode()を使用します
uuid モジュールの getnode() メソッドを利用すると、コンピュータの MAC アドレスを取得できます。
import uuid print (hex(uuid.getnode()))
レンダリング:
出力 MAC アドレスがフォーマットされた形式ではなく、区切り文字が含まれていないことがわかります。
方法 2、getnode() format() を使用します
方法 1 に基づいて、format() メソッドを使用してより適切な出力形式を取得します
import uuid print ("格式化的MAC地址为 : ", end="") print (':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1]))
レンダリング:
整形されたMACアドレスが出力されていることがわかりますが、このように記述したコードは非常に複雑に見えます。複雑さのプロパティを使用するには、 re() メソッドを追加します。
メソッド 3. getnode() findall() re()
import re, uuid print ("格式化且不太复杂的MAC地址为 : ", end="") print (':'.join(re.findall('..', '%012x' % uuid.getnode())))
を使用します。出力:
要約: 以上がこの記事の全内容です。皆さんの学習に役立つことを願っています。
以上がPythonを使用してMACアドレスを生成する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境
