PHP malformed IP address and host. What is this? - php

I track downloads from my website by adding a database entry for each download that contains the IP address and host of the downloading person.
I use this PHP code to retrieve the IP address
isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]
and the host with the PHP function gethostbyaddr, passing the IP address.
This has been working perfectly fine for years, until something weird happened:
Today I saw two download entries for which both the IP address and host are 2a02:2028:1aa:2dc1:854e:9ccc:b423:7c93.
Domaintools says it's a "Malformed Domain or IP".
Could someone tell me what that thing is and why it's malformed?
I don't think it's a bot or something because my stuff can only be downloaded by real persons, so I'm really confused?!

It's not malformed.
It's an IPv6 address.
It's probably someone tunnelling or proxying from their IPv6 network into the IPv4 internet.
DomainTools doesn't seem to be IPv6 aware, or at least not the tool you used, but this one is.

Related

Why am i getting different ip by using get content - PHP

So why am I need my own ip by using get content? I want to use some tv channels which is m3u8 file and using m3u8?wmsAuthSign=code
wmsAuthSign code is changing everytime the page refresh it self and they are getting ip adrress inside of that code.
So i can't play the tv channel by my servers ip !
the code i gave down below is just an example :D
<?php
$myURL = "https://whatismyipaddress.com/ip-lookup";
$lines = file($myURL);
echo $lines[145];
?>
Is there any way that i can change it to my one ip adresse?
If you mean the client (browsers) IP:
That code is being executed on your server, so the machine fetching that URL is your server. The response then has your server's IP address.
If you want to get the IP address of the user that's accessing the server, you could use some of the $_SERVER variables (like $_SERVER['REMOTE_ADDR']) but due to the way the internet works, that may not be the user's IP address.
Your best bet there is to use javascript that runs on the user's browser to identify the user's IP address - though, since that is really under the user's control, you can't be certain it's accurate either.
If you mean you're getting the IP of a different server, not your web server: the method you're using only determines the IP address of the server acting as a gateway to the greater internet. If your web server is behind a firewall, you'll be getting the IP of the firewall. You may want to identify the web server's local IP address instead.
Because the server is executing the PHP code and is requesting the website, if you want to get the IP address of the current user see How to get the client IP address in PHP?

How to tell if they connected through domain name or IP in PHP

I know that's a confusing title but let me explain. I'm working on a website and I want it to look differently depending on if they used the ip or example.com in the address bar. Is it possible to get what address they used in PHP? I know you can change it with header('Location:example.com'); but I need to know how to get it.
Print out
$_SERVER['HTTP_HOST']
will resolve your problem.
Servers are always accessed by their IP addresses. If someone types in the hostname 'example.org' the device will resolve it using a DNS server (large list of hostnames and their respective ip addresses), the DNS server will give the device the IP address and the device will connect to that IP.
TCP/IPv4 packets can only be sent to 32-bit ipv4 addresses.
TCP/IPv6 packets can only be sent to 128-bit ipv6 addresses.
On the page you want to know from what location a visitor came in from, do this:
var_dump($_SERVER);
You will see all the $_SERVER values you'll use to get different values you require.

error when i used my ip address instead of localhost as URL

I have downloaded WAMP server and i have written a very very simple php code and saved it in
C:\wamp\www\php_lear
folder. I have tested it using chrome giving url as
{localhost/php_lear/eg2.php}
And it worked fine. This uses a database stored in phpmyadmin. I found out my ip address from google 117.195.230.41. When i give
{117.195.230.41/php_lear/eg2.php}
as URL it gives me 404 not found
"The requested URL '/php_lear/eg2.php' was not found on this server"
Please help. I have no knowledge of ips and urls and very new to this field and yeah i have added this ip as allowed user in phpmyadmin. I actually want to use this in my android app.
The IP address you get from google is the IP address of your router. It does not point to your computer. As some ppl said, besides there is different ports to use in a connection and your WAMP installation is "listening" on the port 80 of your computer (127.0.0.1)
When you access to the 117.195.230.41 you are accessing to the IP that your Internet Service Provider gives to your installation. So you need to access your router and redirect all the querys to the 117.195.230.41 on port 80 to your port 80 and the IP of your computer in your local network.
The Public/Private IP confusion is a common misunderstanding.
Mike is correct. Due to how IP addressing works, there's a limited number of addresses. As a result, Network Address Translation was born (among other irrelevant things). The Public IP is what the world sees when it glances at your traffic. You want your Private IP, the one your router's DHCP has given you.
1) Open command prompt.
2) Issue the command "ipconfig" (without the quotes).
3) Find your "IPv4 Address". That's the one you want.
Additionally, follow Surt's suggestion to get everything working properly.

Get IPv6 in PHP

Can some one help me to read out the IPv6?
I tried this Working with IPv6 Addresses in PHP but it does not work for me..
There is no problem to get the IPv4 over
echo $_SERVER['REMOTE_ADDR'];
but can someone tell me how i get the IPv6?
This Site can read both (IPv4 and IPv6): http://ipv6-test.com/api/. But I try it without any api, is that possible?
Thanks
You have the right idea, but the request has to be made with IPv6 if you want an IPv6 address.
The site you link to probably works by having a page that loads resource from a server only accessible via IPv6. If it works, then you know the address.
I would just build a site that fires off AJAX requests to the same server, one via IPv4 and one via IPv6. Use its IP addresses to rule out any local DNS issues where IPv6 may not be supported.

How do you set the proxy IP with Phproxy?

I just downloaded PhProxy from here. When I went to some IP locator site my IP was a Dallas/Texas IP. Is there any way to change the IP PhProxy uses? I couldn't find a way to do it.
PHProxy - like all proxies - accepts requests from any of a number of IPs and acts on their behalf to fulfill that request. The IP you're seeing is almost certainly the IP address of your webserver, and no you can't edit some setting to change it. Your server makes a request to some address and includes its own address - this is how the remote end knows how to answer back. You couldn't change this with a PHProxy setting even if you wanted to - if you could, your packets wouldn't get back to you.
You could get a different webhost, if a Dallas-located IP is a real problem, but it would be locked to the new webhost just the same. Webservers can't exactly IP-hop...

Categories