Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

[Share] Website Resolving [Share]

this is really simple Python, but still its good to share code.

This can be very usefull if you like to hit sites ect.

the following code is for Python v2.7.3

Code
import socket
print socket.gethostbyname("google.com")

the output would be googles IP address.

now, with the knowledge of the code above, you can easily upgrade the code.
Here is an example:
Code
import socket, pyperclip, time
    site = raw_input("\n Website: ")
    print("\n {#} Resolving IP Address for %s... {#}" % (site))
    time.sleep(1)
    print("\n {#} IP Address = %s" % socket.gethostbyname(site))
    time.sleep(1)
    print("\n {#} Copying IP Address To Clipboard...")
    pyperclip.copy(socket.gethostbyname(site))
    spam = pyperclip.paste()
    print("\n {#} IP Address Copied To Clipboard!")

so with that script, you can easily type the name of the site & resolve it. Very useful.

There are many things you can do with the module socket, but ill leave that up to you.
I hope you may benefit from this.
Why would you sleep inbetween prints? Seems pointless to mee.
Also, "%s" % whatever is deprecated, look at str.format() instead.
(Apr 10, 2013 05:38 AM)PigBacon Wrote:  Why would you sleep inbetween prints? Seems pointless to mee.
Also, "%s" % whatever is deprecated, look at str.format() instead.

because I don't like the idea of everything printing at once, and sleep seems like a good solution for that.
Pretty basic, but that's ok. It's a good idea to handle exceptions. What if the site doesn't exist? I could type efawegawedgadga.com and chances are it isn't a real site. So put your gethostbyname into a try clause, then for your exception you could say "Not a real website". Not bad though. P.s here is my copy2clipboard function in-case you actually care lol.

Code
def addToClipBoard(text):
    command = 'echo ' + text.strip() + '| clip'
    os.system(command)
(Apr 10, 2013 05:41 AM)Skyla Blue Wrote:  Pretty basic, but that's ok. It's a good idea to handle exceptions. What if the site doesn't exist? I could type efawegawedgadga.com and chances are it isn't a real site. So put your gethostbyname into a try clause, then for your exception you could say "Not a real website". Not bad though. P.s here is my copy2clipboard function in-case you actually care lol.

Code
def addToClipBoard(text):
    command = 'echo ' + text.strip() + '| clip'
    os.system(command)

people can do that if they want, I was just sharing something basic and simple, but useful.
Yeah they can. I'm just saying, it's good to handle exceptions even in simple things.
(Apr 10, 2013 05:46 AM)Skyla Blue Wrote:  Yeah they can. I'm just saying, it's good to handle exceptions even in simple things.

I agree. But if you are using this to hit sites like I said in the thread, you would know if the site you are hitting exists or not, lol. But still I know where you're coming from.
ooo. I've never seen that library before pyperclip.

Looks pretty nifty, lets you take the ip adress and puts it in your clipboard.

Does that support win only?
(Apr 10, 2013 11:29 AM)K.ing Wrote:  ooo. I've never seen that library before pyperclip.

Looks pretty nifty, lets you take the ip adress and puts it in your clipboard.

Does that support win only?

Sorry for the late reply.

Also, no. It supports just about any OS.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by SIM-3437924May 1, 2020 07:59 AM 2 154 May 1, 2020 07:59 AM
Last Post: dracx
[.NET] by Leroy Jethro GibbsOct 13, 2013 10:17 AM 6 264 Oct 13, 2013 10:17 AM
Last Post: Fhoto.
[.NET] by RA1NDec 22, 2012 03:01 PM 0 151 Dec 22, 2012 03:01 PM
Last Post: RA1N