How i know a IP is connected/normal or disconnected from LAN in PHP?












-2














I have a database where i have stored all IP address. Now i want to know these IP address is connected/normal or disconnected. I have tried:



$add     = "example.com";
$result = checkdnsrr($add, "MX");
var_dump($result);


Its return boolean true or false. But i have IP address which is not connected dns. But how can i know the IP is active/normal/connected or disconnected?










share|improve this question
























  • checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
    – atoms
    13 hours ago










  • @atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
    – Chonchol Mahmud
    13 hours ago










  • not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
    – atoms
    13 hours ago
















-2














I have a database where i have stored all IP address. Now i want to know these IP address is connected/normal or disconnected. I have tried:



$add     = "example.com";
$result = checkdnsrr($add, "MX");
var_dump($result);


Its return boolean true or false. But i have IP address which is not connected dns. But how can i know the IP is active/normal/connected or disconnected?










share|improve this question
























  • checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
    – atoms
    13 hours ago










  • @atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
    – Chonchol Mahmud
    13 hours ago










  • not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
    – atoms
    13 hours ago














-2












-2








-2


1





I have a database where i have stored all IP address. Now i want to know these IP address is connected/normal or disconnected. I have tried:



$add     = "example.com";
$result = checkdnsrr($add, "MX");
var_dump($result);


Its return boolean true or false. But i have IP address which is not connected dns. But how can i know the IP is active/normal/connected or disconnected?










share|improve this question















I have a database where i have stored all IP address. Now i want to know these IP address is connected/normal or disconnected. I have tried:



$add     = "example.com";
$result = checkdnsrr($add, "MX");
var_dump($result);


Its return boolean true or false. But i have IP address which is not connected dns. But how can i know the IP is active/normal/connected or disconnected?







php ip lan






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago

























asked 13 hours ago









Chonchol Mahmud

1,90711439




1,90711439












  • checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
    – atoms
    13 hours ago










  • @atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
    – Chonchol Mahmud
    13 hours ago










  • not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
    – atoms
    13 hours ago


















  • checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
    – atoms
    13 hours ago










  • @atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
    – Chonchol Mahmud
    13 hours ago










  • not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
    – atoms
    13 hours ago
















checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
– atoms
13 hours ago




checkdnsrr will get domain information where available. This is not the same as a user being connected. To detect this you would need to implement some sort of a background list where IP addresses are stored against a date/last visited. It could also be archived with the use of js
– atoms
13 hours ago












@atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
– Chonchol Mahmud
13 hours ago




@atoms so how can i achieve my goal? Can you give me any idea in PHP or JS?
– Chonchol Mahmud
13 hours ago












not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
– atoms
13 hours ago




not really. I've pointed you in the right direction. Abdul has given some good information too. Think about having a list in memory. Each user has a record in the list. Just maintain the list's data and you will have what you want
– atoms
13 hours ago












2 Answers
2






active

oldest

votes


















1














LONG POLLING is BAD



As far as I have understood your question, you just want to check if the particular client is connected or not.



You will have to setup a cron job in PHP with a continuous loop which will be long polled by XHR (AJAX with Jquery etc) setting a status = true. So, when a user disconnects, the XHR will be broken and a status will be set = false. Thus you can check if a user is connected or not. However, please note that Long Polling is really resource intensive and is not appreciated.



I would highly suggest you to use go with Node and Websockets etc.



I could write a code for PHP Cron job and settle your problem but I don't appreciate Long Polling + Cron Job for it.






share|improve this answer























  • Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
    – Chonchol Mahmud
    13 hours ago










  • @ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
    – Abdul Jabbar Dumrai
    13 hours ago






  • 1




    @ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
    – Abdul Jabbar Dumrai
    13 hours ago










  • Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
    – Chonchol Mahmud
    13 hours ago



















0














if you want to check if the website is alive then you can do it like this:



$add     = "example.com";
$result = false;
if($fp = fsockopen($add, 80, $errno, $errstr, 10)){
fclose($fp);
$result = true;
}
var_dump($result);


// edit: so you want to know if the IP is present in your local network ? if so you can use ping like:



function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "x08x00x7dx4bx00x00x00x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $host, null);

$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255))
$result = microtime(true) - $ts;
else $result = false;
socket_close($socket);

return $result;
}

$present = ping('192.168.0.100');





share|improve this answer























  • I want to check IP is connected or disconnected to LAN.
    – Chonchol Mahmud
    13 hours ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942587%2fhow-i-know-a-ip-is-connected-normal-or-disconnected-from-lan-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














LONG POLLING is BAD



As far as I have understood your question, you just want to check if the particular client is connected or not.



You will have to setup a cron job in PHP with a continuous loop which will be long polled by XHR (AJAX with Jquery etc) setting a status = true. So, when a user disconnects, the XHR will be broken and a status will be set = false. Thus you can check if a user is connected or not. However, please note that Long Polling is really resource intensive and is not appreciated.



I would highly suggest you to use go with Node and Websockets etc.



I could write a code for PHP Cron job and settle your problem but I don't appreciate Long Polling + Cron Job for it.






share|improve this answer























  • Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
    – Chonchol Mahmud
    13 hours ago










  • @ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
    – Abdul Jabbar Dumrai
    13 hours ago






  • 1




    @ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
    – Abdul Jabbar Dumrai
    13 hours ago










  • Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
    – Chonchol Mahmud
    13 hours ago
















1














LONG POLLING is BAD



As far as I have understood your question, you just want to check if the particular client is connected or not.



You will have to setup a cron job in PHP with a continuous loop which will be long polled by XHR (AJAX with Jquery etc) setting a status = true. So, when a user disconnects, the XHR will be broken and a status will be set = false. Thus you can check if a user is connected or not. However, please note that Long Polling is really resource intensive and is not appreciated.



I would highly suggest you to use go with Node and Websockets etc.



I could write a code for PHP Cron job and settle your problem but I don't appreciate Long Polling + Cron Job for it.






share|improve this answer























  • Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
    – Chonchol Mahmud
    13 hours ago










  • @ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
    – Abdul Jabbar Dumrai
    13 hours ago






  • 1




    @ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
    – Abdul Jabbar Dumrai
    13 hours ago










  • Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
    – Chonchol Mahmud
    13 hours ago














1












1








1






LONG POLLING is BAD



As far as I have understood your question, you just want to check if the particular client is connected or not.



You will have to setup a cron job in PHP with a continuous loop which will be long polled by XHR (AJAX with Jquery etc) setting a status = true. So, when a user disconnects, the XHR will be broken and a status will be set = false. Thus you can check if a user is connected or not. However, please note that Long Polling is really resource intensive and is not appreciated.



I would highly suggest you to use go with Node and Websockets etc.



I could write a code for PHP Cron job and settle your problem but I don't appreciate Long Polling + Cron Job for it.






share|improve this answer














LONG POLLING is BAD



As far as I have understood your question, you just want to check if the particular client is connected or not.



You will have to setup a cron job in PHP with a continuous loop which will be long polled by XHR (AJAX with Jquery etc) setting a status = true. So, when a user disconnects, the XHR will be broken and a status will be set = false. Thus you can check if a user is connected or not. However, please note that Long Polling is really resource intensive and is not appreciated.



I would highly suggest you to use go with Node and Websockets etc.



I could write a code for PHP Cron job and settle your problem but I don't appreciate Long Polling + Cron Job for it.







share|improve this answer














share|improve this answer



share|improve this answer








edited 13 hours ago

























answered 13 hours ago









Abdul Jabbar Dumrai

3,12153260




3,12153260












  • Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
    – Chonchol Mahmud
    13 hours ago










  • @ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
    – Abdul Jabbar Dumrai
    13 hours ago






  • 1




    @ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
    – Abdul Jabbar Dumrai
    13 hours ago










  • Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
    – Chonchol Mahmud
    13 hours ago


















  • Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
    – Chonchol Mahmud
    13 hours ago










  • @ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
    – Abdul Jabbar Dumrai
    13 hours ago






  • 1




    @ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
    – Abdul Jabbar Dumrai
    13 hours ago










  • Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
    – Chonchol Mahmud
    13 hours ago
















Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
– Chonchol Mahmud
13 hours ago




Please could you write up PHP cron Job or give me some useful links for node and websockets. Appreciated.
– Chonchol Mahmud
13 hours ago












@ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
– Abdul Jabbar Dumrai
13 hours ago




@ChoncholMahmud itnext.io/… for more, you can Google for Node + Websockets and it will bring a list of tons of websites teaching it.
– Abdul Jabbar Dumrai
13 hours ago




1




1




@ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
– Abdul Jabbar Dumrai
13 hours ago




@ChoncholMahmud for more robust system, use Socket.io with Node. As this will cover a wide area of old browsers as well. Off Course, if you are newbie to Node, you will have to learn it but trust me it's really easy and worth learning it.
– Abdul Jabbar Dumrai
13 hours ago












Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
– Chonchol Mahmud
13 hours ago




Thank you very much for you good suggestion. Yes, I am newbie in Node. That's why i want solve this problem with PHP.
– Chonchol Mahmud
13 hours ago













0














if you want to check if the website is alive then you can do it like this:



$add     = "example.com";
$result = false;
if($fp = fsockopen($add, 80, $errno, $errstr, 10)){
fclose($fp);
$result = true;
}
var_dump($result);


// edit: so you want to know if the IP is present in your local network ? if so you can use ping like:



function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "x08x00x7dx4bx00x00x00x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $host, null);

$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255))
$result = microtime(true) - $ts;
else $result = false;
socket_close($socket);

return $result;
}

$present = ping('192.168.0.100');





share|improve this answer























  • I want to check IP is connected or disconnected to LAN.
    – Chonchol Mahmud
    13 hours ago
















0














if you want to check if the website is alive then you can do it like this:



$add     = "example.com";
$result = false;
if($fp = fsockopen($add, 80, $errno, $errstr, 10)){
fclose($fp);
$result = true;
}
var_dump($result);


// edit: so you want to know if the IP is present in your local network ? if so you can use ping like:



function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "x08x00x7dx4bx00x00x00x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $host, null);

$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255))
$result = microtime(true) - $ts;
else $result = false;
socket_close($socket);

return $result;
}

$present = ping('192.168.0.100');





share|improve this answer























  • I want to check IP is connected or disconnected to LAN.
    – Chonchol Mahmud
    13 hours ago














0












0








0






if you want to check if the website is alive then you can do it like this:



$add     = "example.com";
$result = false;
if($fp = fsockopen($add, 80, $errno, $errstr, 10)){
fclose($fp);
$result = true;
}
var_dump($result);


// edit: so you want to know if the IP is present in your local network ? if so you can use ping like:



function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "x08x00x7dx4bx00x00x00x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $host, null);

$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255))
$result = microtime(true) - $ts;
else $result = false;
socket_close($socket);

return $result;
}

$present = ping('192.168.0.100');





share|improve this answer














if you want to check if the website is alive then you can do it like this:



$add     = "example.com";
$result = false;
if($fp = fsockopen($add, 80, $errno, $errstr, 10)){
fclose($fp);
$result = true;
}
var_dump($result);


// edit: so you want to know if the IP is present in your local network ? if so you can use ping like:



function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "x08x00x7dx4bx00x00x00x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $host, null);

$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255))
$result = microtime(true) - $ts;
else $result = false;
socket_close($socket);

return $result;
}

$present = ping('192.168.0.100');






share|improve this answer














share|improve this answer



share|improve this answer








edited 13 hours ago

























answered 13 hours ago









Kazz

384313




384313












  • I want to check IP is connected or disconnected to LAN.
    – Chonchol Mahmud
    13 hours ago


















  • I want to check IP is connected or disconnected to LAN.
    – Chonchol Mahmud
    13 hours ago
















I want to check IP is connected or disconnected to LAN.
– Chonchol Mahmud
13 hours ago




I want to check IP is connected or disconnected to LAN.
– Chonchol Mahmud
13 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942587%2fhow-i-know-a-ip-is-connected-normal-or-disconnected-from-lan-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas