1

Код:

import os

def get_ip_address(url):
    command = 'host' + url
    process = os.popen(command)
    results = str(process.read())
    marker = results.find('has address') + 12
    return results[marker:].splitlines()[0]


print(get_ip_address('google.com'))

Ошибка:

File "C:\Users\Karen\Desktop\PocketSploit\modules\ip_address.py", line 9, in get_ip_address
    return results[marker:].splitlines()[0]
IndexError: list index out of range
2
  • возможно вы используете ОС Windows, которая не имеет такой комманды (host). потому с точки синтаксиса всё правильно, но на выходе в переменной results нет ничего так как она равна None 20 авг 2018 в 9:53
  • Что за команда (host)? Что ты хочешь получить вообще?
    – Lo_okiMan
    30 июл 2019 в 21:28

2 ответа 2

1

Судя по всему, process.read() возвращает пустую строку.

Пример для воспроизведения ошибки:

In [19]: results = str("")

In [20]: marker = results.find('has address') + 12

In [21]: marker
Out[21]: 11

In [22]: results[marker:].splitlines()
Out[22]: []

In [23]: results[marker:].splitlines()[0]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-23-6962e431f3ce> in <module>()
----> 1 results[marker:].splitlines()[0]

IndexError: list index out of range
1

когда Вы определяете переменную "command", она становится равной hostgoogle.com, подозреваю, что нужно получить host google.com, попробуйте заменить command = 'host' + url на command = 'host ' + url.

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.