Sinisterly
Personal IP checker. - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Personal IP checker. (/Thread-Personal-IP-checker)



Personal IP checker. - Stocking - 01-24-2014

It's basically an easy way to check your IP address without "whatismyip.com" or whatever that website is.

Import yo' shit, dawg.

We only need four imports. Pretty simple, right?

Code:
import socket
import os
import sys
import time

(PSST, I know I can use commas, I choose not to when importing modules)

Definitions

We will define events "loop" and "close".
This is where the OS module comes into play.

Code:
def loop(event):
    os.startfile("ipchecker.py"),close(begin)
    
def close(event):
    os.system('taskkill /PID %d /F' % os.getpid())

IP checker itself

This is pretty simple. All you do is load a few messages and then do an if, elif, else statement.

Code:
msg = print("[IP CHECK]Loading."), time.sleep(2), print("[IP CHECK]Loaded."), time.sleep(1)
begin = print("[IP CHECK] %s " % socket.gethostbyname(socket.gethostname())), time.sleep(1)
answer = input("[IP CHECK]Reload? ")
if answer == "yes":
    loop(begin), os.system("clear")
elif answer == "no":
    try:
        print("[IP CHECK]Process killed.")
        close(begin)
    except Exception as e:
        print(e)
else:
    print("[IP CHECK]Invalid command."), time.sleep(2), loop(begin)

EVERYBODY NOW!

This is the code all together.

Code:
import socket
import os
import sys
import time

def loop(event):
    os.startfile("ipchecker.py"),close(begin)
    
def close(event):
    os.system('taskkill /PID %d /F' % os.getpid())

msg = print("[IP CHECK]Loading."), time.sleep(2), print("[IP CHECK]Loaded."), time.sleep(1)
begin = print("[IP CHECK] %s " % socket.gethostbyname(socket.gethostname())), time.sleep(1)
answer = input("[IP CHECK]Reload? ")
if answer == "yes":
    loop(begin), os.system("clear")
elif answer == "no":
    try:
        print("[IP CHECK]Process killed.")
        close(begin)
    except Exception as e:
        print(e)
else:
    print("[IP CHECK]Invalid command."), time.sleep(2), loop(begin)

Hope you like what took my five minutes to code.

Somewhere down the road, I will be adding an IP hider.


RE: Personal IP checker. - Pidiot - 01-24-2014

love in the beginning you were kind of getto haha


RE: Personal IP checker. - 3SidedSquare - 01-24-2014

The following code is completely unnecessary
Code:
msg = print("[IP CHECK]Loading."), time.sleep(2), print("[IP CHECK]Loaded."), time.sleep(1)



RE: Personal IP checker. - Stocking - 01-24-2014

(01-24-2014, 10:28 PM)3SidedSquare Wrote: The following code is completely unnecessary
Code:
msg = print("[IP CHECK]Loading."), time.sleep(2), print("[IP CHECK]Loaded."), time.sleep(1)
that's there for effect.