
Multi‑threaded Python tool to query FOFA API, extract custom fields (IP, port, cert, TLS, etc.), deduplicate results, and resume interrupted searches.
A powerful multi‑threaded Python tool to query the FOFA (Fofa.so) API, extract selected fields, and save unique results with intelligent formatting.
ip, port, title, cert.*, tls.*, …)domains_*.txt, ips_*.txt)list command shows all valid fields)raw_input – easily portable to Python 3)requests libraryInstall the dependency:
pip install requests
🔧 Configuration
API_KEY = "PUT UR TOKEN HERE"
import os
API_KEY = os.getenv("FOFA_API_KEY", "your_default_key")
🚀 Usage
Run the script:
python fofa_searcher.py
You will be prompted interactively:
[?] Enter FOFA query: domain="example.com"
[?] Enter max page to scrape [Default: 1]: 5
Each page returns up to SIZE_DEFAULT results.
[?] Enter fields [Default: host,ip,port]: host,ip,port,title,cert.sn
Type list to see all valid fields (basic, certificate, TLS).
All results are saved in OUTPUT_DIR with a descriptive filename, e.g. results/domains_example_com_20250315_143022.txt
📂 Output Examples
Single field – nicely labeled:
IP: 93.184.216.34
Port: 443
Title: Example Domain
Multiple fields – compact format:
93.184.216.34 | Port:443 | [Example Domain] | {US}
Certificate / TLS fields – clear labels:
Cert Serial Number: 01:23:45:...
TLS version: TLSv1.2
🧩 Valid Fields
The tool supports all common FOFA fields plus certificate (cert.) and TLS (tls.) fields.
Basic fields (partial list)
ip, port, protocol, base_protocol, host, domain, title, server, country, region, city, os, asn, org, banner, header, body, cname, icp, jarm, icon, fid, status_code, product
Certificate fields
cert, cert.sn, cert.not_after, cert.not_before, cert.domain, cert.subject.org, cert.subject.cn, cert.issuer.org, cert.issuer.cn, cert.is_valid, cert.is_match, cert.is_equal
TLS fields
tls.version, tls.ja3s
Type list during field prompt to see them all.
⚙️ Configuration Variables (inside script)
Variable Default Description CONCURRENT_THREADS 10 Number of parallel page requests SIZE_DEFAULT 100 Results per page (max FOFA allows) OUTPUT_DIR results Directory where output files are saved
📝 Important Notes
· The script uses en.fofa.info as the API endpoint. · Deduplication is based on the first field value (e.g., IP or domain) and is case‑insensitive. · Long strings (titles, banners, headers) are truncated in the output for readability. · If you interrupt the script (Ctrl+C), it exits gracefully. · The script currently uses Python 2 raw_input. To run with Python 3, replace raw_input with input and adjust the print statements.
❗ Troubleshooting
Issue Solution API_KEY not set Edit the script and add your key. Invalid field(s) Run the script and type list to see allowed fields. No results Check your FOFA query syntax and API credits. ImportError: No module named requests Install requests with pip install requests. UnicodeEncodeError The script already handles UTF‑8 encoding; ensure your terminal supports it.
📄 License
MIT License – free to use and modify for your own reconnaissance needs. Note: FOFA API usage is subject to FOFA’s terms of service.
🙌 Acknowledgements
Built for the FOFA search engine – a powerful IoT and asset search platform.
Happy hunting! 🔍