ローカルのシステム情報を得る

「ローカルのシステム情報を得る」の編集履歴(バックアップ)一覧はこちら

ローカルのシステム情報を得る」(2009/07/08 (水) 13:54:40) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

platformというモジュールで色々調べられます。 [[Python ライブラリリファレンス>http://www.m-takagi.org/docs/python/lib/module-platform.html]] [[light bird>http://www.lightbird.net/py-by-example/platform-module.html]] とりあえずFefora7-x64にて。 #highlight(python){{ >>> import platform >>> platform.uname() ('Linux', 'machineName', '2.6.23.15-80.fc7', '#1 SMP Sun Feb 10 16:52:18 EST 2008', 'x86_64', 'x86_64') >>> platform.system() 'Linux' >>> platform.node() 'pern' >>> platform.platform() 'Linux-2.6.23.15-80.fc7-x86_64-with-redhat-7-Moonshine' }} XP-32bit #highlight(python){{ >>> import platform >>> platform.uname() ('Windows', 'machineName', 'XP', '5.1.2600', '', '') >>> platform.system() 'Windows' >>> platform.node() 'machineName' >>> platform.platform() 'Windows-XP-5.1.2600-SP2' }} またはsys.platformでも調べることが出来ます。 Fedora7 -x64 #highlight(python){{ >>> import sys >>> sys.platform 'linux2' }}} XP-32bit #code(python){{ >>> import sys >>> sys.platform 'win32' }} **wxを使う wxを使っているなら、こんなのもあります。 Fedora7 -x64 #highlight(python){{ >>> import wx >>> wx.GetUserId() u'hajime' >>> wx.GetOsDescription() u'Linux 2.6.23.15-80.fc7 x86_64' >>> wx.GetHostName() u'machineName' >>> }} XP-32bit #highlight(python){{ >>> import wx >>> wx.GetUserId() u'hajime' >>> wx.GetOsDescription() u'Windows XP (build 2600, Service Pack 2)' >>> wx.GetHostName() u'machineName' >>> }} 以下の関数もチェックです。 wx.Now() wx.GetLocalTime() wx.DisplaySize() wx.GetUserId() wx.GetOsDescription() wx.GetHostName() wx.version() **socketを使う socketを使ってローカルホスト名とIPを得ることもできるようです。 [[ローカルホスト名やIPアドレスを得る>http://papasan.org/pythonrecipe/web/X_e3_83_ad_e3_83_bc_e3_82_ab_e3_83_ab_e3_83_9b_e3_82_b9_e3_83_88_e5_90_8d_e3_82_84IP_e3_82_a2_e3_83_89_e3_83_ac_e3_82_b9_e3_82_92_e5_be_97_e3_82_8b]] が、linuxでこの方法を試したのですが127.0.0.1しか返りません。 #highlight(python){{ >>>host = socket.gethostname() >>>ip = socket.gethostbyname_ex(host) >>>print ip[2][0] 127.0.0.1 }} これを乗り切るにはちょっとしたトリックが必要。 #highlight(python){{ >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.connect(("www.google.com", 80)) >>> ip = s.getsockname() >>> s.close() >>> print ip ('192.168.x.x', 55623) }} ダサいですね。諦めてifconfigから取った方が良さそう。 **実行ユーザーの取得 uidを取得 import os print os.getuid() ユーザー名 import pwd, os print pwd.getpwuid(os.getuid())[0] **ビデオカードの情報を取得する(windows) [[List Video Controller Properties>http://www.thescriptlibrary.com/default.asp?Action=Display&Level=Category3&ScriptLanguage=Python&Category1=Hardware&Category2=Video%20and%20Display&Title=List%20Video%20Controller%20Properties]]
platformというモジュールで色々調べられます。 [[Python ライブラリリファレンス>http://www.m-takagi.org/docs/python/lib/module-platform.html]] [[light bird>http://www.lightbird.net/py-by-example/platform-module.html]] とりあえずFefora7-x64にて。 #highlight(python){{ >>> import platform >>> platform.uname() ('Linux', 'machineName', '2.6.23.15-80.fc7', '#1 SMP Sun Feb 10 16:52:18 EST 2008', 'x86_64', 'x86_64') >>> platform.system() 'Linux' >>> platform.node() 'pern' >>> platform.platform() 'Linux-2.6.23.15-80.fc7-x86_64-with-redhat-7-Moonshine' }} XP-32bit #highlight(python){{ >>> import platform >>> platform.uname() ('Windows', 'machineName', 'XP', '5.1.2600', '', '') >>> platform.system() 'Windows' >>> platform.node() 'machineName' >>> platform.platform() 'Windows-XP-5.1.2600-SP2' }} またはsys.platformでも調べることが出来ます。 Fedora7 -x64 #highlight(python){{ >>> import sys >>> sys.platform 'linux2' }}} XP-32bit #highlight(python){{ >>> import sys >>> sys.platform 'win32' }} **wxを使う wxを使っているなら、こんなのもあります。 Fedora7 -x64 #highlight(python){{ >>> import wx >>> wx.GetUserId() u'hajime' >>> wx.GetOsDescription() u'Linux 2.6.23.15-80.fc7 x86_64' >>> wx.GetHostName() u'machineName' >>> }} XP-32bit #highlight(python){{ >>> import wx >>> wx.GetUserId() u'hajime' >>> wx.GetOsDescription() u'Windows XP (build 2600, Service Pack 2)' >>> wx.GetHostName() u'machineName' >>> }} 以下の関数もチェックです。 wx.Now() wx.GetLocalTime() wx.DisplaySize() wx.GetUserId() wx.GetOsDescription() wx.GetHostName() wx.version() **socketを使う socketを使ってローカルホスト名とIPを得ることもできるようです。 [[ローカルホスト名やIPアドレスを得る>http://papasan.org/pythonrecipe/web/X_e3_83_ad_e3_83_bc_e3_82_ab_e3_83_ab_e3_83_9b_e3_82_b9_e3_83_88_e5_90_8d_e3_82_84IP_e3_82_a2_e3_83_89_e3_83_ac_e3_82_b9_e3_82_92_e5_be_97_e3_82_8b]] が、linuxでこの方法を試したのですが127.0.0.1しか返りません。 #highlight(python){{ >>>host = socket.gethostname() >>>ip = socket.gethostbyname_ex(host) >>>print ip[2][0] 127.0.0.1 }} これを乗り切るにはちょっとしたトリックが必要。 #highlight(python){{ >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.connect(("www.google.com", 80)) >>> ip = s.getsockname() >>> s.close() >>> print ip ('192.168.x.x', 55623) }} ダサいですね。諦めてifconfigから取った方が良さそう。 **実行ユーザーの取得 uidを取得 import os print os.getuid() ユーザー名 import pwd, os print pwd.getpwuid(os.getuid())[0] **ビデオカードの情報を取得する(windows) [[List Video Controller Properties>http://www.thescriptlibrary.com/default.asp?Action=Display&Level=Category3&ScriptLanguage=Python&Category1=Hardware&Category2=Video%20and%20Display&Title=List%20Video%20Controller%20Properties]]

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。