FOFA API¶
- class fofa.Client(key='', base_url='', proxies=None)[source]¶
Bases:
object
A class representing the FOFA client.
- Parameters:
key (str) – The Fofa api key. If not specified, it will be read from the FOFA_KEY environment variable.
base_url (str) – The base URL of the FOFA API. Defaults to ‘https://fofa.info’.
proxies (dict) – A proxies array for the requests library, e.g. {‘https’: ‘your proxy’}
- can_use_next()[source]¶
Check if the “search_next” API can be used.
- Returns:
True if the “search_next” API can be used, False otherwise.
- Return type:
bool
- get_userinfo()[source]¶
Get user info for current user.
- Returns:
User information in JSON format.
- Return type:
dict
- Raises:
FofaException – If an error occurs during the API request.
- Example:
The returned JSON result will be in the following format:
{ "username": "sample", "fofacli_ver": "4.0.3", "fcoin": 0, "error": false, "fofa_server": true, "avatar": "https://nosec.org/missing.jpg", "vip_level": 0, "is_verified": false, "message": "", "isvip": false, "email": "username@sample.net" }
- search(query_str, page=1, size=100, fields='', opts={})[source]¶
Search data in FOFA.
- Parameters:
query_str (str) –
The search query string.
- Example 1:
’ip=127.0.0.1’
- Example 2:
’header=”thinkphp” || header=”think_template”’
page (int) – Page number. Default is 1.
size (int) – Number of results to be returned in one page. Default is 100.
fields (str) – Comma-separated list of fields to be included in the query result. Example: ‘ip,city’
opts (dict) – Additional options for the query. This should be a dictionary of key-value pairs.
- Returns:
Query result in JSON format.
- Return type:
dict
{ "results": [ [ "111.**.241.**:8111", "111.**.241.**", "8111" ], [ "210.**.181.**", "210.**.181.**", "80" ] ], "mode": "extended", "error": false, "query": "app=\"网宿科技-公司产品\"", "page": 1, "size": 2 }
- search_host(host, detail=False, opts={})[source]¶
Search for host information based on the specified IP address or domain.
- Parameters:
host (str) – The IP address or domain of the host to search for.
detail (bool) – Optional. Specifies whether to show detailed information. Default is False.
opts (dict) – Optional. Additional options for the search. Default is an empty dictionary.
- Returns:
The query result in JSON format.
- Return type:
dict
{ "error": false, "host": "78.48.50.249", "ip": "78.48.50.249", "asn": 6805, "org": "Telefonica Germany", "country_name": "Germany", "country_code": "DE", "protocol": [ "http", "https" ], "port": [ 80, 443 ], "category": [ "CMS" ], "product": [ "Synology-WebStation" ], "update_time": "2022-06-11 08:00:00" }
- search_next(query_str, fields='', size=100, next='', full=False, opts={})[source]¶
Query the next page of search results.
- Parameters:
query_str –
The search query string.
- Example 1:
’ip=127.0.0.1’
- Example 2:
’header=”thinkphp” || header=”think_template”’
fields (str) – The fields to be included in the response. Default: ‘host,ip,port’
size (int) – The number of results to be returned per page. Default: 100 Maximum: 10,000
next (str) – The ID for pagination. The next value is returned in the response of previous search query. If not provided, the first page of results will be returned.
full (bool) – Specify if all data should be searched. Default: False (search within the past year) Set to True to search all data.
opts (dict) – Additional options for the search.
- Returns:
The query result in JSON format.
- Return type:
dict
- search_stats(query_str, size=5, fields='', opts={})[source]¶
Query the statistics of the search results.
- Parameters:
query_str (str) –
The search query string.
- Example 1:
’ip=127.0.0.1’
- Example 2:
’header=”thinkphp” || header=”think_template”’
size (int) – The number of results to be aggregated for each item. Default: 5
fields (str) – The fields to be included in the aggregation. Example: ‘ip,city’
opts (dict) – Additional options for the search.
- Returns:
query result in json format
{ "distinct": { "ip": 1717, "title": 411 }, "lastupdatetime": "2022-06-17 13:00:00", "aggs": { "title": [ { "count": 35, "name": "百度一下,你就知道" }, { "count": 25, "name": "百度网盘-免费云盘丨文件共享软件丨超大容量丨存储安全" }, { "count": 16, "name": "百度智能云-登录" }, { "count": 2, "name": "百度翻译开放平台" } ], "countries": [] }, "error": false }