Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- '''
- www.google.com [172.217.175.100]に ping を送信しています 32 バイトのデータ:
- (以下省略)
- '''
- with open('./pingデータ.txt', 'r', encoding='UTF-8') as file:
- data = file.read()
- ptn_url = re.compile(r'([\w-]+\.)+[\w-]+(/[\w ./?%&=-]*)?')
- # ptn_ip = re.compile(r'\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]')
- ptn_ip = re.compile(
- 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])\]')
- if result_url := ptn_url.search(data):
- output_url = result_url.group(0)
- else:
- output_url = 'URLは不明'
- if result_ip := ptn_ip.search(data):
- output_ip = result_ip.group(0).strip('[]')
- else:
- output_ip = 'IPアドレスは不明'
- print(output_url + ' の ip は ' + output_ip + ' です')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement