Участник:StasFomin/Bookmarks/Stegano — различия между версиями

Материал из DISCOPAL
Перейти к: навигация, поиск
(Добавлена закладка linux - How to get hard disk serial number using Python - Stack Overflow)
Строка 2: Строка 2:
 
=== 2020-08 ===
 
=== 2020-08 ===
  
 +
* 2020-08-05, 12:30:58: [https://stackoverflow.com/questions/4193514/how-to-get-hard-disk-serial-number-using-python/4194146#4194146 linux - How to get hard disk serial number using Python - Stack Overflow]
 +
*: <html><span class="kwd">with</span><span class="pln"> open</span><span class="pun">(</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv</span><span class="pun">[</span><span class="lit">1</span><span class="pun">],</span><span class="pln"> </span><span class="str">"rb"</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">as</span><span class="pln"> fd</span><span class="pun">:</span><span class="pln">    </span><span class="com"># tediously derived from the monster struct defined in &lt;hdreg.h&gt;</span><span class="pln">    </span><span class="com"># see comment at end of file to verify</span><span class="pln">    hd_driveid_format_str </span><span class="pun">=</span><span class="pln"> </span><span class="str">"@ 10H 20s 3H 8s 40s 2B H 2B H 4B 6H 2B I 36H I Q 152H"</span><span class="pln">    </span><span class="com"># Also from &lt;hdreg.h&gt;</span><span class="pln">    HDIO_GET_IDENTITY </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0x030d</span><span class="pln">    </span><span class="com"># How big a buffer do we need?</span><span class="pln">    sizeof_hd_driveid </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">calcsize</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">)</span><span class="pln">      </span><span class="com"># ensure our format string is the correct size</span><span class="pln">    </span><span class="com"># 512 is extracted using sizeof(struct hd_id) in the c code</span><span class="pln">    </span><span class="kwd">assert</span><span class="pln"> sizeof_hd_driveid </span><span class="pun">==</span><span class="pln"> </span><span class="lit">512</span><span class="pln">      </span><span class="com"># Call native function</span><span class="pln">    buf </span><span class="pun">=</span><span class="pln"> fcntl</span><span class="pun">.</span><span class="pln">ioctl</span><span class="pun">(</span><span class="pln">fd</span><span class="pun">,</span><span class="pln"> HDIO_GET_IDENTITY</span><span class="pun">,</span><span class="pln"> </span><span class="str">" "</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> sizeof_hd_driveid</span><span class="pun">)</span><span class="pln">    fields </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">unpack</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">,</span><span class="pln"> buf</span><span class="pun">)</span><span class="pln">    serial_no </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">10</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln">    model </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">15</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln">    </span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hard Disk Model: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> model</span><span class="pun">)</span><span class="pln">    </span><span class="kwd">print</span><span class="pun">(</span><span class="str">"  Serial Number: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> serial_no</span><span class="pun">)</span></html>
 +
<!-- NEXT BOOKMARK -->
 
* 2020-08-04, 03:05:33: [http://sourceware.org/binutils/docs/ld/VERSION.html VERSION - Untitled]
 
* 2020-08-04, 03:05:33: [http://sourceware.org/binutils/docs/ld/VERSION.html VERSION - Untitled]
 
* 2020-08-03, 14:43:19: [https://habr.com/ru/company/veeam/blog/471226/ Linux многоликий: как работать на любом дистрибутиве / Блог компании Veeam Software / Хабр]
 
* 2020-08-03, 14:43:19: [https://habr.com/ru/company/veeam/blog/471226/ Linux многоликий: как работать на любом дистрибутиве / Блог компании Veeam Software / Хабр]

Версия 12:30, 5 августа 2020

2020

2020-08

  • 2020-08-05, 12:30:58: linux - How to get hard disk serial number using Python - Stack Overflow
    with open(sys.argv[1], "rb") as fd: # tediously derived from the monster struct defined in <hdreg.h> # see comment at end of file to verify hd_driveid_format_str = "@ 10H 20s 3H 8s 40s 2B H 2B H 4B 6H 2B I 36H I Q 152H" # Also from <hdreg.h> HDIO_GET_IDENTITY = 0x030d # How big a buffer do we need? sizeof_hd_driveid = struct.calcsize(hd_driveid_format_str) # ensure our format string is the correct size # 512 is extracted using sizeof(struct hd_id) in the c code assert sizeof_hd_driveid == 512 # Call native function buf = fcntl.ioctl(fd, HDIO_GET_IDENTITY, " " * sizeof_hd_driveid) fields = struct.unpack(hd_driveid_format_str, buf) serial_no = fields[10].strip() model = fields[15].strip() print("Hard Disk Model: %s" % model) print(" Serial Number: %s" % serial_no)
  • 2020-08-04, 03:05:33: VERSION - Untitled
  • 2020-08-03, 14:43:19: Linux многоликий: как работать на любом дистрибутиве / Блог компании Veeam Software / Хабр
    Вы можете компилировать программы современным компилятором, в современном дистрибутиве, и использовать динамическую линковку со старыми заголовками glibc, чтобы ваша программа запускалась на древнегреческих дистрибутивах, но при этом не требовала собственного libc.
    См. github.com/wheybags/glibc_version_header и github.com/sulix/bingcc

2020-07

Навигация