IP adresses

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

IP adresses

 
0
  #1
Nov 5th, 2005
Ok, Im still really shaky w/useing python with other programs. So here is my question, is it possible to create just a very small program that grabs my IP adress, copys it, and then sends it to certain IM buddys? The reason I am asking this is beacause my friends and I play a multiplayer game but, the game requires me to give out my IP to every singe person who wants to play, not to mention I also use a program called teamspeak that requires them to type my ip. If it can't send it to im buddys is it possible to just have it copy it to the clipboard?

Help apprecaited. :cheesy:
Blender is by far the best free 3D computer Graphics program and it is expandable with python! GoTo www.blender3d.org
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,032
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 933
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: IP adresses

 
0
  #2
Nov 6th, 2005
It might depend on what OS you are using, but here is one way ...
[php]# socket.getaddrinfo returns a list of tuples
# tuple[4][0] of each list element is the IP address

import socket

addrs = socket.getaddrinfo(socket.gethostname(), None)
for addr in addrs:
print addr[4][0]
[/php]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: IP adresses

 
0
  #3
Nov 6th, 2005
Wait so all i need to do is use that code and it will copy it to my clip board? Or will it just print it in the DOS box? Oh and I am using XP for Windows. And what is a tuples?
Blender is by far the best free 3D computer Graphics program and it is expandable with python! GoTo www.blender3d.org
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: IP adresses

 
0
  #4
Nov 7th, 2005
This is not very efficient, but you could get your ip using a webbased service
  1. import urllib2
  2. def getip():
  3. webaddress = "http://www.getip.com"
  4. page = urllib2.urlopen(webaddress)
  5. pagetolines = page.readlines()
  6. for i in pagetolines:
  7. if i.find('<title>GetIP') != -1:
  8. ipline = i
  9. break
  10. ip = ipline.split()[-1].replace("</title>","")
  11. return ip
  12. print getip()

I am not sure how to get that on you clipboard.
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: IP adresses

 
0
  #5
Nov 7th, 2005
Originally Posted by vegaseat
It might depend on what OS you are using, but here is one way ...
[php]# socket.getaddrinfo returns a list of tuples
# tuple[4][0] of each list element is the IP address

import socket

addrs = socket.getaddrinfo(socket.gethostname(), None)
for addr in addrs:
print addr[4][0]
[/php]
I just tested your code, that just gets the internal ip, would he need his external IP?
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,032
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 933
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: IP adresses

 
0
  #6
Nov 7th, 2005
Good question, I am not familiar with the program called teamspeak.

The socket module brings up both IPs on Windows as long as you are connected, otherwise only the internal IP.

You might have to go to wxPython to handle the ClipBoard.

A tuple is an immutable collection of objects separated by commas, usually enclosed in (). In the socket code just print addrs to see what it looks like.
Last edited by vegaseat; Nov 7th, 2005 at 3:12 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: IP adresses

 
0
  #7
Nov 7th, 2005
using pywin32 adding to the clipboard is easy.

  1. import win32clipboard, urllib2
  2.  
  3. # this function just gets the ip from reading page source, and parisng it out
  4. def getip():
  5. webaddress = "http://www.getip.com"
  6. page = urllib2.urlopen(webaddress)
  7. pagetolines = page.readlines()
  8. for i in pagetolines:
  9. if i.find('<title>GetIP') != -1:
  10. ipline = i
  11. break
  12. ip = ipline.split()[-1].replace("</title>","")
  13. return ip
  14.  
  15. clippedtext = getip()
  16.  
  17. # this function just places the ip into the clipboard, it takes its parameter from getip
  18. def clippy(text):
  19. win32clipboard.OpenClipboard()
  20. win32clipboard.EmptyClipboard()
  21. win32clipboard.SetClipboardText(text)
  22. win32clipboard.CloseClipboard()
  23.  
  24. clippy(clippedtext)
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: IP adresses

 
0
  #8
Nov 8th, 2005
How about Tkinter I've learned basic programming in that but i dont know if i can learn wx Python or Pywin32 but if i have to then i dont mind learning that in place of Tkinter.
Blender is by far the best free 3D computer Graphics program and it is expandable with python! GoTo www.blender3d.org
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: IP adresses

 
0
  #9
Nov 8th, 2005
Originally Posted by vegaseat
Good question, I am not familiar with the program called teamspeak.

The socket module brings up both IPs on Windows as long as you are connected, otherwise only the internal IP.

You might have to go to wxPython to handle the ClipBoard.

A tuple is an immutable collection of objects separated by commas, usually enclosed in (). In the socket code just print addrs to see what it looks like.
Oh, and if you goto goteamspeak.com then it might help you get aquainted with the program, all it is, is a live chat program that uses mics and speakers instead of cell phones (or house phones), but beacause of the way it is set up you cant just click on a link to join a server, you need the ip of the server(the computer)
Blender is by far the best free 3D computer Graphics program and it is expandable with python! GoTo www.blender3d.org
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: IP adresses

 
0
  #10
Nov 8th, 2005
Oh and I am reeeeeeeeeeaaaaaaaaaalllllllly shaky with using classes, that is probably the thing I am most having trouble with when it comes to Python and Tkinter.[I just can't fully grasp the consept (ie. don;t understand why self is in there that really bugs me)]
Blender is by far the best free 3D computer Graphics program and it is expandable with python! GoTo www.blender3d.org
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC