Advertisement
Guest User

Untitled

a guest
Feb 5th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import re
  2.  
  3. '''
  4. www.google.com [172.217.175.100]に ping を送信しています 32 バイトのデータ:
  5. (以下省略)
  6. '''
  7.  
  8. with open('./pingデータ.txt', 'r', encoding='UTF-8') as file:
  9. data = file.read()
  10.  
  11. ptn_url = re.compile(r'([\w-]+\.)+[\w-]+(/[\w ./?%&=-]*)?')
  12. # ptn_ip = re.compile(r'\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]')
  13. ptn_ip = re.compile(
  14. r'\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\]')
  15.  
  16. if result_url := ptn_url.search(data):
  17. output_url = result_url.group(0)
  18. else:
  19. output_url = 'URLは不明'
  20.  
  21. if result_ip := ptn_ip.search(data):
  22. output_ip = result_ip.group(0).strip('[]')
  23. else:
  24. output_ip = 'IPアドレスは不明'
  25.  
  26. print(output_url + ' の ip は ' + output_ip + ' です')
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement