I am developing a simple port scanner using Python, Scapy, nmap module. I want to detect if the host which I apply the port scan is a router or not. How can I identify or guess if the host is a router?
You cannot detect a router using a port scan since not all routers expose ports. Routers are used for routing IP packets at Layer 3 of the OSI model and are used to bridge two different computer networks.
You can detect a router by doing what the traceroute command does.
Assuming you know what the IP address of the target router is then you would Send a ICMP Echo message with a TTL value of one to a destination IP that you suspect is on the other side of the network as the target router. If you get a ICMP Time Exceeded reply back from the IP of the target router, then you know it is a router. You might need to do this with some trial and error as you might not know the IP addresses on the other side of the router.
You can easily test this using the traceroute command against a target router then mimic the same behavior using the Scapy API to send ICMP Echo messages with TTL of one and test it out.