How to ping ip address - laravel - php

I hope this is not a duplicate but I could not find a laravel IP address ping..., I have this:
Ping::check('http://example.com'); which returns 200 if website is alive or 0 if not, but it doesnt work on DNS or IPs...
For example, the DNS is: server.sols-rpg.com:7777 and it also has a port as you can see 7777, it is a SAMP server, if I go to a DNS lookup, some will also tell me that it is online and running, or some will just give me its IP, but still, how can I ping it?

Related

Unknown SSL certificate showing up on ssllabs.com server test

I've recently ran a SSL test (ssllabs.com/ssltest) on our website: kimarineadventures.com.au
Two certificates showed up from different servers. (first one is ours) I'm looking for a solution on how to remove the other one. This is causing errors to some users (website loads unsecure).
Your domain was registered through crazydomains.com.au , and they manage your domain's DNS as well. The second IP address you see on the ssllabs.com report is one of theirs.
To solve the problem you'll need to log on to crazydomains.com.au, open the DNS settings and delete the AAAA record(s) with that IP address (2404:8280:a222:bbbb:bba1:78:ffff:ffff). Leave the A record(s) as they are, and don't touch anything else.
It may take a few minutes to take effect, but that should do it.

PHP Check if Hostname resolved to local machine

I want to use PHP to check if a specified host name is resolving to the server on which the PHP script is running. By host name, I'm mean the same as a domain name in my particular context.
I say for example, let's say I have a server and it's public IP address is 123.123.123.123 or something similar. My DNS server is resolving two domains to this IP address: domain1.com and domain2.com . I'm accessing the PHP page on the server by domain1.com but I want the script to tell me if domain2.com is resolving to the server and return an appropriate result, like echoing 'yes' or 'no'.
I'm not sure how to approach this. I'm thinking of two possibilities:
Try something similar to a 'ping' of the hostname and see if there's a response, though I don't think this will work because it's local to local and may require the hostname to be resolved in the server's hosts file, which defeats the point of this (I want to see if the hostname is resolving for other clients on the Internet, not the local machine), or
check the hostname's DNS server to see if it resolves to the server's public IP, in which case I'd have to get the public IP somehow in PHP.
How would I approach this?
An example PHP script would be:
function host_resolves($host){
// get server public IP
// check if hostname is a valid domain name
// try to connect to the hostname's DNS server
// query the DNS server and compare IP (maybe in A record?) to public IP
// split off a sub-domain and check for a CNAME if needed
}
if(host_resolves('domain2.com')){
echo 'yep!';
}
else{
echo 'nup :(';
}

"php_connect_nonb() failed: Operation now in progress (115)" happens intermittently

We send some files across to a third party with a PHP cron job via FTP.
However sometimes we get the following error:
ErrorException [ 2 ]: ftp_put(): php_connect_nonb() failed: Operation
now in progress (115) ~ MODPATH/fileop/classes/Drivers/Fileop/Ftp.php [ 37 ]
When I say "sometimes" I mean exactly that; most times it goes across fine but about 1 in 5 times we get that error. It's not to do with the files themselves, because they will go happily if we try again.
We've found similar issues online - relating to a bug in PHP with NAT devices or to do with firewall configuration but again the implication is that if this were the case it would never work.
So, why would this work some times and not others?
ftp_set_option($ftpconn, FTP_USEPASVADDRESS, false);
This line of code before setting passivity of the connection ftp_pasv($ftpconn, true);
Solved my problem
FTP(S) uses random ports to set up data connections; an intermittent success rate indicates that not all ports are allowed by a firewall on the client and/or server machines. The port range for incoming (PASV) data connections can be set in the FTP server.
This page has a nice summary:
The easy way is to simply allow FTP servers and clients unlimited
access through your firewall, but if you like to limit their access to
"known" ports, you have to understand the 4 different scenarios.
1) The FTP server should be allowed to accept TCP connections to port
21, and to make TCP connections from port 20 to any (remote ephemeral)
port.
2) The FTP server should be allowed to accept TCP connections to port
21, AND to accept TCP connections to any ephemeral port as well!
3) The FTP client should be allowed to make TCP connections to port
21, and to accept TCP connections from port 20 to any ephemeral port.
4) The FTP client should be allowed to make TCP connections to port
21, and to make TCP connections to any other (remote ephemeral) port
as well!
So, I'm writing this answer after doing some investigation on my FTP server and reading the link you provided elitehosts.com.
I'm using FileZilla FTP server, and there is a specific setting that I had to enter to make it work. Going into the server settings, there is an area titled "Passive mode settings". In that dialog, there is an area titled "IPv4 specific", and within that area there is a setting labeled "External Server IP Address for passive mode transfers:". It's a radio button selection set, and it was on "Default", but since the FTP server is NAT'ed, I changed that radio selection from "Default" to "Use the following IP:" and entered in the external-facing IP address of my gateway provided by my ISP.
After I set this up, it worked! Not terribly sure if your FTP server is NAT'ed, but I thought I would provide the answer on this thread because it seems related.
In addition to Cees answer, I am running vsftp on ec2 and had to comment out the listen_ipv6=YES, listen=YES then "service vsftpd restart".
Although documentation says it will listen on ipv4 as well it wasn't and this resolved the issue.
For me all I had to do was to remove the ftp_pasv( $ftpconn, true ); and everything worked perfectly. I'm not yet sure why but I am trying to find out and I will surely come back when I do get the reason behind it.
This should be a comment under jj_dev2 comment, but I cannot add one due to reputation. But maybe it will be helpful for someone, so I post it here.
We had the same issue as described in the original post. In our case it worked with many customers - except one.
The solution in jj_dev2 comment did work for us. So we investigated what does ftp_set_option($conn, FTP_USEPASVADDRESS, false) actually do. And based on that we found out that in fact customer's FTPS server was configured incorrectly.
In response to PASV command (ftp_pasv($conn, true)) FTP server returns an IP address which the PHP FTP client then will use for data transfers. In our case the FTP server was returning an internal IP address and not the public IP address that we connect to. Customer had to fix their FTP server settings so FTP server would send external IP address in the PASV command response.

server IP address of my website rather than domain IP

Hi I need to know the IP address of my website to give to my payment gateway. I know I can find an IP address by going to any of the websites which come up on google, but my understanding is that they give the domain's IP address which may be different from the IP address of the server the site is hosted on.
So how to I find out what the IP address of my server is?
Thanks :)
Run this from the command line to get your server's outgoing IP:
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
The server's IP address can be found with the $_SERVER variable:
<?php
echo $_SERVER['SERVER_ADDR'];
you can also do a quick PHP output of
<?php
phpinfo();
?>
it will contain all the values you need for your host details (just don't leave this file public after you use it).
What do you mean by the domain IP? The IP returned from a DNS lookup when querying your domain? This is most likely equal to the IP of your (shared) server, otherwise your website would be unreachable.
An exception to that is when the IP your DNS record represents belongs to a proxy server, which forwards the request to the real server.
You could always get the public IP address of the server by visiting www.whatismyip.com from the server.

My IP is showing up wrong in PHP home server

Ok simple enough
<?PHP
echo $_SERVER[REMOTE_ADDR];
?>
Ok maybe not, I my IP is currently 72.184.212.85 however the code above which I am using on an IP blocking system for a script shows my IP as my home server IP of 127.0.0.1
So when I go to my script my IP is shown as 127.0.0.1 but when I go to other websites it is shown as 72.184.212.85
How can I get the first value to show on my test server?
$_SERVER['REMOTE_ADDR'] will always show the IP address from which the request came. If you access your own script on your own computer within your own network, your external IP address never comes into play. The request would have to leave your local network and then come back in for the external address to show up, but if it's all local, that'll never happen.
You'll have to make your server publicly accessible and then access it from the public address. I'm guessing you're currently using localhost to access your server?
run your server say port 8080 and then forward the port in your router so it's public to the internet. Then visit your webpage/phpscript from http://72.184.212.85:8080 instead of http://localhost:8080.
Here is a ridiculous solution that I wouldn't recommend:
Register your home IP with a domain name, then see where the request came from via URL:
$url = $_SERVER["SERVER_NAME"];
or
$url = $_SERVER["HTTP_HOST"];
and then do a dns lookup of that result, which should return the IP it's registered to, ie your external IP.
$ext_ip = gethostbyaddr($url);
The only reason this wouldn't work (so sorry if I'm wrong), is if SERVER_NAME uses the same method as "REMOTE_HOST", which is a reverse DNS lookup, which won't resolve, as your internal IP won't be registered to that domain name. An easy way to check is to do either:
phpinfo();
and see what the environmental variables are.

Categories