reverse_dns
Resolve an IP address to its associated domain name using reverse DNS lookup.
Instructions
Perform a reverse DNS lookup for an IP address.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- src/sounding/server.py:197-215 (handler)The async handler function for the 'reverse_dns' tool. It validates the IP address, performs a reverse DNS lookup using dnspython (dns.reversename.from_address + dns.resolver.resolve PTR), and returns a dict with 'ip', 'hostnames', and optionally 'error'.
@mcp.tool() async def reverse_dns(ip: str) -> dict: """Perform a reverse DNS lookup for an IP address.""" ip = validate_host(ip) try: ipaddress.ip_address(ip) except ValueError: raise ValueError(f"reverse_dns requires an IP address, got: {ip!r}") try: rev_name = dns.reversename.from_address(ip) answers = await asyncio.get_event_loop().run_in_executor( None, lambda: dns.resolver.resolve(rev_name, "PTR") ) hostnames = [str(r) for r in answers] except Exception as exc: return {"ip": ip, "hostnames": [], "error": str(exc)} return {"ip": ip, "hostnames": hostnames} - src/sounding/server.py:193-195 (registration)The @mcp.tool() decorator that registers reverse_dns as an MCP tool on the FastMCP server instance.
# --------------------------------------------------------------------------- # 5. reverse_dns # --------------------------------------------------------------------------- - tests/test_tools.py:208-213 (helper)Test for the reverse_dns tool that verifies the expected dict shape (ip and hostnames/error keys present).
@pytest.mark.asyncio async def test_reverse_dns_shape(): """reverse_dns should return the expected dict shape.""" result = await reverse_dns("8.8.8.8") assert "ip" in result assert "hostnames" in result or "error" in result - tests/test_tools.py:24-24 (helper)Import of reverse_dns from sounding.server in the test file.
reverse_dns,