Hack Forums
[Python] IP_Grabber (external, active interfaces, machines IP) 2 years ago - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] IP_Grabber (external, active interfaces, machines IP) 2 years ago (/showthread.php?tid=4436489)



IP_Grabber (external, active interfaces, machines IP) 2 years ago - Ahmed X Blade - Sep 7, 2014

In my early coding days. I created a script that will grab certen IP's like external IP, the machine's IP, the active interfaces and the IP associated with the active interface. I made this code for training. I just found this code on my HDD recently and I find it interesting wich command's I used to grab the IP's. I dont know maybe you find this interesting and usefull in a way.


Code
"""IP_grabber by The_R (2011)"""
import socket
import os

print "\033[1;32m[+] \033[1;m External IP: "
cmd = "wget -q -O - http://myexternalip.com/raw"
print
os.system(cmd)
print
Interface_ip = socket.gethostbyname(socket.gethostname())
print "\033[1;32m[+] \033[1;m Machine's IP: "
print
print Interface_ip
print
print "\033[1;34m[!]\033[1;m Active interfaces:"
active_interfaces = "ifconfig -a | grep 'Link encap' | awk '{ print $1 '}"
os.system(active_interfaces)
print

cmd1 = "ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
cmd2 = "ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"

interface = raw_input("\033[1;31m[?]\033[1;m What is your interface? ")
if interface == 'wlan0':
    print
    print "\033[1;32m[+] \033[1;m IP associated with your interface: %s" % (interface)
    print
    os.system(cmd1)
elif interface == 'eth0':
    print
    print "\033[1;32m[+] \033[1;m IP associated with your interface: %s" % (interface)
    print
    os.system(cmd2)
else:
    print
    print "\033[1;31mNo IP found\033[1;m"


Regards,


* - botnetswatnet - Sep 16, 2014

Bro, post the script on pastebin. Don't center the code, it fucks up the formatting.


* - K-On! - Sep 17, 2014

Why bother making a Python script if you're just going to use system calls? Why not bash?


* - xMoD - Sep 19, 2014

(Sep 16, 2014 11:48 AM)botnetswatnet Wrote:  Bro, post the script on pastebin. Don't center the code, it fucks up the formatting.

Theres been many threads where posters tell him this, but Im not sure he speaks "common sense" or can hardly understand us :/ but it would be nice


Plus python is meant to be cross-OS, so to use system calls specific to linux is also not very...pleasant


* - xXRippedMasterXx - Sep 19, 2014

Ok this guy is just not even trying anymore like, everyone tells him to put his code in pastebin yet he never does it, and then he gets neg repped for not doing it and yet he does it again. I am wondering if he even can read english....


* - Ahmed X Blade - Sep 24, 2014

Thanks For Alll i t s Simple script :D


* - K-On! - Sep 24, 2014

(Sep 24, 2014 07:27 AM)Ahmed X Blade Wrote:  Thanks For Alll i t s Simple script :D

You Are Welcomeeee! C o u l d You fucking read the feedback before replying :D


* - Ahmed X Blade - Jun 6, 2015

Ok Brother After New Thread I WIll Paste In Pastebin


* - The_R - Jun 6, 2015

I coded this script. And posted this on Vip--Hackforums. If you are explaining my script please give credits.