tools.py 466 B

123456789101112131415161718192021222324
  1. import hashlib
  2. import socket
  3. def sha1(text: str):
  4. """
  5. 十六进制数字字符串形式摘要值
  6. @param text: 字符串文本
  7. @return: 摘要值
  8. """
  9. _sha1 = hashlib.sha1()
  10. _sha1.update(text.encode("utf-8"))
  11. return _sha1.hexdigest()
  12. def get_host_ip():
  13. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  14. try:
  15. s.connect(('8.8.8.8', 80))
  16. ip = s.getsockname()[0]
  17. finally:
  18. s.close()
  19. return ip