Skip to content

Instantly share code, notes, and snippets.

@gjportegies
Last active April 30, 2024 06:25
Show Gist options
  • Select an option

  • Save gjportegies/853754d9feb94db5f2e26a5772b44dbb to your computer and use it in GitHub Desktop.

Select an option

Save gjportegies/853754d9feb94db5f2e26a5772b44dbb to your computer and use it in GitHub Desktop.
ClaudeBot (ips)
3.12.41.106
3.14.246.254
3.16.218.62
3.133.121.160
3.138.114.38
3.143.218.146
3.145.47.253
18.116.24.105
18.116.63.174
18.189.180.76
18.190.156.212
18.217.144.32
18.221.15.15
18.222.117.109
18.224.214.215
18.226.150.175
import re
def extract_ip_user_agent(log_file, user_agent, output_file):
ip_addresses = set()
# Regular expression pattern to match IP addresses
ip_pattern = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
with open(log_file, 'r') as file:
for line in file:
# Check if the line contains the specified user agent
if user_agent in line:
# Extract the IP address using regex
ip_match = re.search(ip_pattern, line)
if ip_match:
ip_addresses.add(ip_match.group())
# Write the extracted IP addresses to the output file
with open(output_file, 'w') as output:
for ip_address in ip_addresses:
output.write(ip_address + '\n')
# Example usage
log_file = 'access.log'
user_agent = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)' # Replace with your desired user agent
output_file = 'output.txt'
extract_ip_user_agent(log_file, user_agent, output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment