Dijit

Get_IP.py

Jun 30th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """"
  5. Author:  Jan Harasym <[email protected]>
  6. Website: dijit.sh
  7.  
  8. Creation Date: 30-06-2014
  9. Last Modified: Mon 30 Jun 2014 19:10:27 BST
  10.  
  11. Description:  
  12. Expected Use:
  13. """
  14.  
  15. from PyQt4 import QtGui
  16. import urllib
  17. import sys
  18.  
  19. def Get_IP():
  20.     try:
  21.         sock = urllib.urlopen("http://eitin.drk.sc/~dijit/ip.php")
  22.     except:
  23.         sock = urllib.urlopen("http://ifconfig.me/")
  24.  
  25.     IP = sock.readline().rstrip()
  26.     del sock
  27.     return(IP)
  28.  
  29. class Small_Window(QtGui.QWidget):
  30.     def __init__(self):
  31.         super(Small_Window, self).__init__()
  32.  
  33.         self.initUI()
  34.  
  35.     def initUI(self):
  36.  
  37.         lbl1 = QtGui.QLabel(Get_IP(), self)
  38.         lbl1.move(10,5)
  39.  
  40.         self.resize(120, 30)
  41.         self.center()
  42.  
  43.         self.setWindowTitle('IP Tracker in Qt/Python')
  44.         self.show()
  45.  
  46.     def center(self):
  47.  
  48.         qr = self.frameGeometry()
  49.         cp = QtGui.QDesktopWidget().availableGeometry().center()
  50.         qr.moveCenter(cp)
  51.         self.move(qr.topLeft())
  52.  
  53. def main():
  54.     print(Get_IP())
  55.     app = QtGui.QApplication(sys.argv)
  56.     ex = Small_Window()
  57.     sys.exit(app.exec_())
  58.  
  59. if __name__ == '__main__':
  60.     main()
Advertisement
Add Comment
Please, Sign In to add comment