Is there any way to check if an IP address is a real IP address or private IP address?
First, private IP addresses are real IP addresses. I assume you mean which IP addresses can be routed on the public Internet vs. which IP addresses cannot.
Check to see if the IP address is in one of the ranges marked as
Global in the IANA IPv4 Special-Purpose Address Registry. If it is, it cannot be routed on the public Internet. Also, multicast addresses (
188.8.131.52/4) cannot be routed on the public Internet.
You can do the same thing for IPv6 with the IANA IPv6 Special-Purpose Address Registry. The globally routable IPv6 addresses all fall in the
2000::/3 range, but there are address ranges within that which are not routable on the public Internet, and any multicast IPv6 address (
ff00::/8) is not routable on the public Internet.