0

I am writing a script that gives back the IP from a website. I have written it successfully, but now I am trying to add some kind of verification to the IP itself ,in order to see if it is down. It is giving me this error:

c:\Users\PC\Desktop>getip.py
  File "C:\Users\PC\Desktop\getip.py", line 21
    conn.connect((ip, port))
       ^
IndentationError: expected an indented block

Here is the script :

# AUTHOR : G19
# Version : 1.0.0v

import time, socket, os, sys, string

print ("#####################################################")
print ("#     SCRIPT : GETIP.PY                             #")
print ("#     AUTHOR : G19                                  #")
print ("#     VERSION: 1.0.0b                               #")
print ("#####################################################")
print ("")

host = raw_input('WEBSITE LINK : ')
ip = socket.gethostbyname(host)
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 80


def getip():
    try:
        conn.connect((ip, port))
        conn.send("Sending packet confirmation")
    except:   
        print ("")
        print ("#####################################################")
        print ("#     STATUS : DOWN                                 #")
        print ("#     IP: " + ip + "                                #")
        print ("#####################################################")
        print ("")
    print ("")
    print ("#####################################################")
    print ("#     STATUS : UP                                   #")
    print ("#     IP: " + ip + "                                #")
    print ("#####################################################")
    print ("")    
    return

getip()
Nic3500
  • 8,144
  • 10
  • 29
  • 40

1 Answers1

2

You are mixing tabs and spaces. The try: line is indented with a tab, the next line with spaces; my editor shows tabs as a line, spaces as dots, when selected:

tab circled

Python expands tabs to 8 spaces, so to Python, there is no difference between the lines.

Don't mix tabs and spaces. Configure your editor to always expand indentation to spaces, and replace all existing tabs with spaces. PEP 8 (the python styleguide) recommends spaces over tabs, as does the Google Python styleguide.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343