Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11915 > unrolled thread

Regarding split text and match from data base

Started byjalaf28@gmail.com
First post2013-11-22 03:28 -0800
Last post2013-11-29 13:58 +0000
Articles 20 on this page of 32 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-22 03:28 -0800
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 09:24 -0500
    Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 16:34 +0100
      Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 10:54 -0500
        Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 17:50 +0100
          Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 13:57 -0500
            Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-23 08:52 +0100
              Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-23 07:05 -0500
                Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-24 17:17 +0100
                  Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-24 11:23 -0500
    Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 20:02 -0800
    Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:09 -0800
    Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:35 -0800
      Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:35 +0100
        Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:36 +0100
      Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-25 09:31 -0500
    Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:32 -0800
    Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:41 -0800
      Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-26 07:20 -0500
        Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-26 21:22 -0800
          Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:29 +0100
            Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:31 +0100
          Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-27 09:57 -0500
            Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 12:27 +0000
              Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 11:01 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 18:51 +0000
                  Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 19:27 -0500
                    Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 02:34 +0000
                      Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 22:47 -0500
                        Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 05:01 +0000
                          Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-29 07:40 -0500
                            Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 13:58 +0000

Page 1 of 2  [1] 2  Next page →


#11915 — Regarding split text and match from data base

Fromjalaf28@gmail.com
Date2013-11-22 03:28 -0800
SubjectRegarding split text and match from data base
Message-ID<676203c7-7d21-4513-92d5-7a9111c2eaa6@googlegroups.com>
Hello All
I just start learning PHP  and i am using 5.4.16 i just want to split the out put of the following and match from the database and print the System name.

here is the Code 

<?php

     ob_start();
     $line=shell_exec("arp -a");
     echo "<pre>;
     echo $line;
     echo "</pre>";  

?>

It shows the output of the command "arp -a" and show the Ip address and  Mac address on the LAN system. i saved the name and the Mac address in the database.
now i want to extaxct the command output and match ["MAc address] with database and show the Particular system name and Ip Address. i try google but not sufficent.

i just want to show th eout put like


IP                 Name               
192.168.1.x         Server1
192.168.1.x         Client1

Thanks
Amit


[toc] | [next] | [standalone]


#11922

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-22 09:24 -0500
Message-ID<l6npev$seh$1@dont-email.me>
In reply to#11915
On 11/22/2013 6:28 AM, jalaf28@gmail.com wrote:
> Hello All
> I just start learning PHP  and i am using 5.4.16 i just want to split the out put of the following and match from the database and print the System name.
>
> here is the Code
>
> <?php
>
>       ob_start();
>       $line=shell_exec("arp -a");
>       echo "<pre>;
>       echo $line;
>       echo "</pre>";
>
> ?>
>
> It shows the output of the command "arp -a" and show the Ip address and  Mac address on the LAN system. i saved the name and the Mac address in the database.
> now i want to extaxct the command output and match ["MAc address] with database and show the Particular system name and Ip Address. i try google but not sufficent.
>
> i just want to show th eout put like
>
>
> IP                 Name
> 192.168.1.x         Server1
> 192.168.1.x         Client1
>
> Thanks
> Amit
>
>
>

Well, you will need to parse the output from your arp command to get the 
list if IP addresses; a regex function such as preg_match_all will help 
you here.

Then you take the output array and use the matching IP addresses to 
search your database.  The function calls will depend on the database 
you're using.

You probably won't find anything like this on the internet; it's not the 
type of thing that's commonly done (although there isn't any problem 
with it).

BTW - why are you using ob_start()?  It just adds overhead to the 
process.  There are very few reasons you ever need to use it.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11925

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-22 16:34 +0100
Message-ID<528F7980.4040500@arnowelzel.de>
In reply to#11915
Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:

> Hello All I just start learning PHP  and i am using 5.4.16 i just
> want to split the out put of the following and match from the
> database and print the System name.
> 
> here is the Code
> 
> <?php
> 
> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
> "</pre>";
> 
> ?>
> 
> It shows the output of the command "arp -a" and show the Ip address
> and  Mac address on the LAN system. i saved the name and the Mac
> address in the database. now i want to extaxct the command output and
> match ["MAc address] with database and show the Particular system
> name and Ip Address. i try google but not sufficent.

You can try explode() using space (' ') as delimiter, see:

<http://php.net/manual/en/function.explode.php>



-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11927

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-22 10:54 -0500
Message-ID<l6numn$s3o$1@dont-email.me>
In reply to#11925
On 11/22/2013 10:34 AM, Arno Welzel wrote:
> Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:
>
>> Hello All I just start learning PHP  and i am using 5.4.16 i just
>> want to split the out put of the following and match from the
>> database and print the System name.
>>
>> here is the Code
>>
>> <?php
>>
>> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>> "</pre>";
>>
>> ?>
>>
>> It shows the output of the command "arp -a" and show the Ip address
>> and  Mac address on the LAN system. i saved the name and the Mac
>> address in the database. now i want to extaxct the command output and
>> match ["MAc address] with database and show the Particular system
>> name and Ip Address. i try google but not sufficent.
>
> You can try explode() using space (' ') as delimiter, see:
>
> <http://php.net/manual/en/function.explode.php>
>
>
>

Arno,

Have you actually looked at the output of arp -a?  From your response, I 
don't think so.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11929

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-22 17:50 +0100
Message-ID<528F8B64.2000804@arnowelzel.de>
In reply to#11927
Jerry Stuckle, 2013-11-22 16:54:

> On 11/22/2013 10:34 AM, Arno Welzel wrote:
>> Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:
>>
>>> Hello All I just start learning PHP  and i am using 5.4.16 i just
>>> want to split the out put of the following and match from the
>>> database and print the System name.
>>>
>>> here is the Code
>>>
>>> <?php
>>>
>>> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>>> "</pre>";
>>>
>>> ?>
>>>
>>> It shows the output of the command "arp -a" and show the Ip address
>>> and  Mac address on the LAN system. i saved the name and the Mac
>>> address in the database. now i want to extaxct the command output and
>>> match ["MAc address] with database and show the Particular system
>>> name and Ip Address. i try google but not sufficent.
>>
>> You can try explode() using space (' ') as delimiter, see:
>>
>> <http://php.net/manual/en/function.explode.php>
>>
>>
>>
> 
> Arno,
> 
> Have you actually looked at the output of arp -a?  From your response, I 
> don't think so.

And where is your answer to the question?

Anyway...

arp -a outputs here (numbers as "x" for privacy reasons):

somename (xxx.xxx.xxx.xxx) at xx:xx:xx:xx:xx:xx [ether] on eth0

So - using explode() on this line with space as delimiter should return
an array with the following elements:

somename
(xxx.xxx.xxx.xxx)
at
xx:xx:xx:xx:xx:xx
[ether]
on
eth0

Then you can use the fourth element which contains the MAC address.

If you get more than one line of output, the lines have to be split
first of course. Therefore I'd recommend using exec() which will return
the output as an array with one element for each line of output.



-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11931

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-22 13:57 -0500
Message-ID<l6o9eb$v2b$1@dont-email.me>
In reply to#11929
On 11/22/2013 11:50 AM, Arno Welzel wrote:
> Jerry Stuckle, 2013-11-22 16:54:
>
>> On 11/22/2013 10:34 AM, Arno Welzel wrote:
>>> Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:
>>>
>>>> Hello All I just start learning PHP  and i am using 5.4.16 i just
>>>> want to split the out put of the following and match from the
>>>> database and print the System name.
>>>>
>>>> here is the Code
>>>>
>>>> <?php
>>>>
>>>> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>>>> "</pre>";
>>>>
>>>> ?>
>>>>
>>>> It shows the output of the command "arp -a" and show the Ip address
>>>> and  Mac address on the LAN system. i saved the name and the Mac
>>>> address in the database. now i want to extaxct the command output and
>>>> match ["MAc address] with database and show the Particular system
>>>> name and Ip Address. i try google but not sufficent.
>>>
>>> You can try explode() using space (' ') as delimiter, see:
>>>
>>> <http://php.net/manual/en/function.explode.php>
>>>
>>>
>>>
>>
>> Arno,
>>
>> Have you actually looked at the output of arp -a?  From your response, I
>> don't think so.
>
> And where is your answer to the question?
>
> Anyway...
>
> arp -a outputs here (numbers as "x" for privacy reasons):
>
> somename (xxx.xxx.xxx.xxx) at xx:xx:xx:xx:xx:xx [ether] on eth0
>
> So - using explode() on this line with space as delimiter should return
> an array with the following elements:
>
> somename
> (xxx.xxx.xxx.xxx)
> at
> xx:xx:xx:xx:xx:xx
> [ether]
> on
> eth0
>
> Then you can use the fourth element which contains the MAC address.
>
> If you get more than one line of output, the lines have to be split
> first of course. Therefore I'd recommend using exec() which will return
> the output as an array with one element for each line of output.
>
>
>

My reply is above - if you bothered to read (which you obviously 
didn't).  Additionally, the output of arp -a is also dependent on the 
operating system and version of arp.  Your way requires much more 
processing than a simple preg_match().

And in this case the regex is pretty simple, and parses the output he 
wants into a multi-dimensional array in one statement.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11941

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-23 08:52 +0100
Message-ID<52905EBA.1080005@arnowelzel.de>
In reply to#11931
Jerry Stuckle, 2013-11-22 19:57:

> On 11/22/2013 11:50 AM, Arno Welzel wrote:
>> Jerry Stuckle, 2013-11-22 16:54:
>>
>>> On 11/22/2013 10:34 AM, Arno Welzel wrote:
>>>> Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:
>>>>
>>>>> Hello All I just start learning PHP  and i am using 5.4.16 i just
>>>>> want to split the out put of the following and match from the
>>>>> database and print the System name.
>>>>>
>>>>> here is the Code
>>>>>
>>>>> <?php
>>>>>
>>>>> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>>>>> "</pre>";
>>>>>
>>>>> ?>
>>>>>
>>>>> It shows the output of the command "arp -a" and show the Ip address
>>>>> and  Mac address on the LAN system. i saved the name and the Mac
>>>>> address in the database. now i want to extaxct the command output and
>>>>> match ["MAc address] with database and show the Particular system
>>>>> name and Ip Address. i try google but not sufficent.
>>>>
>>>> You can try explode() using space (' ') as delimiter, see:
>>>>
>>>> <http://php.net/manual/en/function.explode.php>
>>>>
>>>>
>>>>
>>>
>>> Arno,
>>>
>>> Have you actually looked at the output of arp -a?  From your response, I
>>> don't think so.
>>
>> And where is your answer to the question?
>>
>> Anyway...
>>
>> arp -a outputs here (numbers as "x" for privacy reasons):
>>
>> somename (xxx.xxx.xxx.xxx) at xx:xx:xx:xx:xx:xx [ether] on eth0
>>
>> So - using explode() on this line with space as delimiter should return
>> an array with the following elements:
>>
>> somename
>> (xxx.xxx.xxx.xxx)
>> at
>> xx:xx:xx:xx:xx:xx
>> [ether]
>> on
>> eth0
>>
>> Then you can use the fourth element which contains the MAC address.
>>
>> If you get more than one line of output, the lines have to be split
>> first of course. Therefore I'd recommend using exec() which will return
>> the output as an array with one element for each line of output.
>>
>>
>>
> 
> My reply is above - if you bothered to read (which you obviously 
> didn't).  Additionally, the output of arp -a is also dependent on the 
> operating system and version of arp.  Your way requires much more 
> processing than a simple preg_match().

Yep - I didn't see your other post when I wrote my reply.

And yes, I'm also aware that the output of arp -a depends on the
operating system version. That's why I said - "You can try explode()"
and not "use explode() this will always work". Of course I haven taken
into account that the output format is not the same on all operating
systems.

> And in this case the regex is pretty simple, and parses the output he 
> wants into a multi-dimensional array in one statement.

Sury - regex is pretty simple assuming the OP knows how to use regular
expressions ;-)

But even then additional parsing may be neccessary if arp groups
interfaces and outputs the interface description first and then a list
of entries for that interface like Windows 7 does.

Again - that's why I said "You can try explode()" - it was only a
suggestion, not a complete solution. But preg_metch() is neither.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11943

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-23 07:05 -0500
Message-ID<l6q5lr$p2i$1@dont-email.me>
In reply to#11941
On 11/23/2013 2:52 AM, Arno Welzel wrote:
> Jerry Stuckle, 2013-11-22 19:57:
>
>> On 11/22/2013 11:50 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 2013-11-22 16:54:
>>>
>>>> On 11/22/2013 10:34 AM, Arno Welzel wrote:
>>>>> Am 22.11.2013 12:28, schrieb jalaf28@gmail.com:
>>>>>
>>>>>> Hello All I just start learning PHP  and i am using 5.4.16 i just
>>>>>> want to split the out put of the following and match from the
>>>>>> database and print the System name.
>>>>>>
>>>>>> here is the Code
>>>>>>
>>>>>> <?php
>>>>>>
>>>>>> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>>>>>> "</pre>";
>>>>>>
>>>>>> ?>
>>>>>>
>>>>>> It shows the output of the command "arp -a" and show the Ip address
>>>>>> and  Mac address on the LAN system. i saved the name and the Mac
>>>>>> address in the database. now i want to extaxct the command output and
>>>>>> match ["MAc address] with database and show the Particular system
>>>>>> name and Ip Address. i try google but not sufficent.
>>>>>
>>>>> You can try explode() using space (' ') as delimiter, see:
>>>>>
>>>>> <http://php.net/manual/en/function.explode.php>
>>>>>
>>>>>
>>>>>
>>>>
>>>> Arno,
>>>>
>>>> Have you actually looked at the output of arp -a?  From your response, I
>>>> don't think so.
>>>
>>> And where is your answer to the question?
>>>
>>> Anyway...
>>>
>>> arp -a outputs here (numbers as "x" for privacy reasons):
>>>
>>> somename (xxx.xxx.xxx.xxx) at xx:xx:xx:xx:xx:xx [ether] on eth0
>>>
>>> So - using explode() on this line with space as delimiter should return
>>> an array with the following elements:
>>>
>>> somename
>>> (xxx.xxx.xxx.xxx)
>>> at
>>> xx:xx:xx:xx:xx:xx
>>> [ether]
>>> on
>>> eth0
>>>
>>> Then you can use the fourth element which contains the MAC address.
>>>
>>> If you get more than one line of output, the lines have to be split
>>> first of course. Therefore I'd recommend using exec() which will return
>>> the output as an array with one element for each line of output.
>>>
>>>
>>>
>>
>> My reply is above - if you bothered to read (which you obviously
>> didn't).  Additionally, the output of arp -a is also dependent on the
>> operating system and version of arp.  Your way requires much more
>> processing than a simple preg_match().
>
> Yep - I didn't see your other post when I wrote my reply.
>

Gee, it was only an hour before your post.

> And yes, I'm also aware that the output of arp -a depends on the
> operating system version. That's why I said - "You can try explode()"
> and not "use explode() this will always work". Of course I haven taken
> into account that the output format is not the same on all operating
> systems.
>

Then why tell him something which may not work?

>> And in this case the regex is pretty simple, and parses the output he
>> wants into a multi-dimensional array in one statement.
>
> Sury - regex is pretty simple assuming the OP knows how to use regular
> expressions ;-)
>

There is nothing complicated about his regex.  A little reading of the 
tutorial and one of the regex test engines should get him by very 
easily.  And if he still has problems, posting the output of arp -a here 
and people will help him.

> But even then additional parsing may be neccessary if arp groups
> interfaces and outputs the interface description first and then a list
> of entries for that interface like Windows 7 does.
>

Not if it's done right.  It would be more complicated, but a regex could 
be built to process Windows output, also.

> Again - that's why I said "You can try explode()" - it was only a
> suggestion, not a complete solution. But preg_metch() is neither.
>
>

Shows how little you understand preg_match_all() (not preg_match()).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11952

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-24 17:17 +0100
Message-ID<52922692.8050506@arnowelzel.de>
In reply to#11943
Jerry Stuckle, 2013-11-23 13:05:

> On 11/23/2013 2:52 AM, Arno Welzel wrote:
[...]
>> Again - that's why I said "You can try explode()" - it was only a
>> suggestion, not a complete solution. But preg_metch() is neither.
>>
>>
> 
> Shows how little you understand preg_match_all() (not preg_match()).

Oh - I have a typo in my post due to leaving out "_all" and you assume I
don't understand preg_match_all() - what a brilliant logic ;-)

Well - if it makes you happy, than think so and just ignore my posts.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11953

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-24 11:23 -0500
Message-ID<l6t958$cs0$1@dont-email.me>
In reply to#11952
On 11/24/2013 11:17 AM, Arno Welzel wrote:
> Jerry Stuckle, 2013-11-23 13:05:
>
>> On 11/23/2013 2:52 AM, Arno Welzel wrote:
> [...]
>>> Again - that's why I said "You can try explode()" - it was only a
>>> suggestion, not a complete solution. But preg_metch() is neither.
>>>
>>>
>>
>> Shows how little you understand preg_match_all() (not preg_match()).
>
> Oh - I have a typo in my post due to leaving out "_all" and you assume I
> don't understand preg_match_all() - what a brilliant logic ;-)
>
> Well - if it makes you happy, than think so and just ignore my posts.
>
>

No, it wasn't a typo.  It was your usual show of ignorance.

But then trolls always try to blame their stoopidity on someone else.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11971

Fromjalaf28@gmail.com
Date2013-11-24 20:02 -0800
Message-ID<6044341c-69cc-4129-bcd4-87f25c593c16@googlegroups.com>
In reply to#11915
Thanks For all of you for the reply.

[toc] | [prev] | [next] | [standalone]


#11973

Fromjalaf28@gmail.com
Date2013-11-24 22:09 -0800
Message-ID<e34dd7c9-e60b-4712-b5d0-86534c4e7c29@googlegroups.com>
In reply to#11915
i found the solutio.but its not work properly. because it prints the Ip and System name but no correct. 

here is the code what should i do?

<?php

$out=shell_exec("arp -a");



$ex=explode(" ",$out);

$j=21;  // variable used for Ip address
$k=32;  // varibale used for MAC Address

$ln=mysql_connect("localhost","root","");

if(!$ln)
{
	die("Could not Connect to The Server");
}
mysql_select_db("mysql") or die("Could Not Connect with database");

$rs=mysql_query("select * from mac_add");
echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
while($rr=mysql_fetch_array($rs))
{
	if($rr[0] == $ex[$k])
	{
		//echo  $ex[$j] . "    " . $rr[0] . "<br />";

echo "<tr><td>" .$ex[$j] . "</td><td>" . $rr[0] . "</td> </tr>";
	}
	$j +=21;
	$k +=21;
	
	
}


echo "</table></center>";
?>



its not matching [Comapare with the MAc in the Database]

what should i Do ?

[toc] | [prev] | [next] | [standalone]


#11975

Fromjalaf28@gmail.com
Date2013-11-24 22:35 -0800
Message-ID<61da9f2c-8c49-419f-ae32-ba97326e6e57@googlegroups.com>
In reply to#11915
its new solution it works 
but it skip some computers


<?php

$out=shell_exec("arp -a");



$ex=explode(" ",$out);

$j=21;
$k=32;

$ln=mysql_connect("localhost","root","");

if(!$ln)
{
	die("Could not Connect to The Server");
}
mysql_select_db("mysql") or die("Could Not Connect with database");

$rs=mysql_query("select * from mac_add");
echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
while($rr=mysql_fetch_array($rs))
{
	$rsr=mysql_query("select * from mac_add where mac_id= '$ex[$k]'");
	while( $res=mysql_fetch_array($rsr))
	{
/*	if($rr[0] == $ex[$k])
	{
		//echo  $ex[$j] . "    " . $rr[0] . "<br />";
*/
echo "<tr><td>" .$ex[$j] . "</td><td>" . $res[0] . "</td> </td><td>" .$res[1] . "</td></tr>" ;
	}
	$j +=21;
	$k +=21;
	
	
}


echo "</table></center>";

mysql_close();
?>

[toc] | [prev] | [next] | [standalone]


#11977

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-25 08:35 +0100
Message-ID<5292FDA9.6050902@arnowelzel.de>
In reply to#11975
jalaf28@gmail.com, 2013-11-25 07:35:

> its new solution it works 
> but it skip some computers
> 
> 
> <?php
> 
> $out=shell_exec("arp -a");

Can you post an example of the output of arp -a on your system? Maybe
using preg_match_all() as suggested by Jerry would be the easier way.
Also keep in mind, that arp -a may output more than one line. Maybe this
is the reason, why some computers are skipped - they produce multiple
lines of output, so a simple explode() is not enough.

> $ex=explode(" ",$out);
> 
> $j=21;
> $k=32;

I would prefer:

$ip_address = $out[21];
$mac_address = $out[32];

This makes the remaining code easier to read.

> $ln=mysql_connect("localhost","root","");
> 
> if(!$ln)
> {
> 	die("Could not Connect to The Server");
> }

Shorter - as you already did:

$ln = @mysql_connect("localhost", "root", "") or
      die("Could not connect to the server");

Explanation:

@ in front of the mysql_connect() suppresses any error output by the PHP
runtime.

The construction "function() or die()" will call die() if the function
does return false, since "or" will try to evaluate the second expression
(die()) if the first one (function()) will return false.

In production systems you should also keep in mind that using "root" is
usually not a good idea. It's better to create a separate user who only
has access to the data you need.

> mysql_select_db("mysql") or die("Could Not Connect with database");

You see ;-)

> $rs=mysql_query("select * from mac_add");

Since you only want to get the data for one specific MAC address anway -
assuming your table field is named "mac":

$query = "select * from mac_add where mac='" .
         mysql_real_escape_string($mac_address) .
         "'";
$rs = mysql_query($query);

> echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";

Now you only have one fetch and no loop. Using htmlspecialchars() makes
sure, that the output will not be invalid HTML - but if you are sure,
that you will never have characters like "&", "<", ">" etc. in your
data, you don't need to use it.

if( $rr = mysql_fetch_array($rs) )
{
  echo "<tr>" .
       "<td>" . htmlspecialchars($ip_address) . "</td>" .
       "<td>" . htmlspecialchars($res[0]) . "</td>" .
       "<td>" . htmlspecialchars($res[1]) . "</td>" .
       "</tr>";
}
echo "</table>";
mysql_close();


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11978

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-25 08:36 +0100
Message-ID<5292FE17.9040809@arnowelzel.de>
In reply to#11977
Arno Welzel, 2013-11-25 08:35:

> jalaf28@gmail.com, 2013-11-25 07:35:
> 
>> its new solution it works 
>> but it skip some computers
>>
>>
>> <?php
>>
>> $out=shell_exec("arp -a");
> 
> Can you post an example of the output of arp -a on your system? Maybe
> using preg_match_all() as suggested by Jerry would be the easier way.
> Also keep in mind, that arp -a may output more than one line. Maybe this
> is the reason, why some computers are skipped - they produce multiple
> lines of output, so a simple explode() is not enough.
> 
>> $ex=explode(" ",$out);
>>
>> $j=21;
>> $k=32;
> 
> I would prefer:
> 
> $ip_address = $out[21];
> $mac_address = $out[32];
> 
> This makes the remaining code easier to read.
> 
>> $ln=mysql_connect("localhost","root","");
>>
>> if(!$ln)
>> {
>> 	die("Could not Connect to The Server");
>> }
> 
> Shorter - as you already did:
> 
> $ln = @mysql_connect("localhost", "root", "") or
>       die("Could not connect to the server");
> 
> Explanation:
> 
> @ in front of the mysql_connect() suppresses any error output by the PHP
> runtime.
> 
> The construction "function() or die()" will call die() if the function
> does return false, since "or" will try to evaluate the second expression
> (die()) if the first one (function()) will return false.
> 
> In production systems you should also keep in mind that using "root" is
> usually not a good idea. It's better to create a separate user who only
> has access to the data you need.
> 
>> mysql_select_db("mysql") or die("Could Not Connect with database");
> 
> You see ;-)
> 
>> $rs=mysql_query("select * from mac_add");
> 
> Since you only want to get the data for one specific MAC address anway -
> assuming your table field is named "mac":
> 
> $query = "select * from mac_add where mac='" .
>          mysql_real_escape_string($mac_address) .
>          "'";
> $rs = mysql_query($query);
> 
>> echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
> 
> Now you only have one fetch and no loop. Using htmlspecialchars() makes
> sure, that the output will not be invalid HTML - but if you are sure,
> that you will never have characters like "&", "<", ">" etc. in your
> data, you don't need to use it.
> 
> if( $rr = mysql_fetch_array($rs) )

Ooops - this should be:
if( $res = mysql_fetch_array($rs) )

> {
>   echo "<tr>" .
>        "<td>" . htmlspecialchars($ip_address) . "</td>" .
>        "<td>" . htmlspecialchars($res[0]) . "</td>" .
>        "<td>" . htmlspecialchars($res[1]) . "</td>" .
>        "</tr>";
> }
> echo "</table>";
> mysql_close();



-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11980

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-25 09:31 -0500
Message-ID<l6vmvu$2sp$1@dont-email.me>
In reply to#11975
On 11/25/2013 1:35 AM, jalaf28@gmail.com wrote:
> its new solution it works
> but it skip some computers
>
>
> <?php
>
> $out=shell_exec("arp -a");
>
>
>
> $ex=explode(" ",$out);
>
> $j=21;
> $k=32;
>
> $ln=mysql_connect("localhost","root","");
>
> if(!$ln)
> {
> 	die("Could not Connect to The Server");
> }

It's almost never right to use die() like this in a script.  It 
terminates all processing of the page immediately, causing invalid HTML 
to be generated.  Better is to put out a message and not process any 
code which relies on the connection, but allows the rest of the code and 
HTML to complete normally.

> mysql_select_db("mysql") or die("Could Not Connect with database");
>
> $rs=mysql_query("select * from mac_add");

What is the purpose of this statement?  Why do you want to fetch the 
entire table?

> echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
> while($rr=mysql_fetch_array($rs))

I'm not sure why you want to go through the entire database here.

> {
> 	$rsr=mysql_query("select * from mac_add where mac_id= '$ex[$k]'");

"select *" is also generally not a good idea.  It is better to specify 
the exact columns you want.  That way if you change the database later, 
it will cause fewer problems.  For instance, if you add a large BLOB 
column, you won't be retrieving a lot of data you aren't using.  Also, 
if you DROP a column or change the columns name, the error will show up 
on the SELECT statement and not later.

> 	while( $res=mysql_fetch_array($rsr))

I prefer mysql_fetch_assoc().  It is clearer because you identify the 
columns by name and not by index, helping to self-document the code.

> 	{
> /*	if($rr[0] == $ex[$k])
> 	{
> 		//echo  $ex[$j] . "    " . $rr[0] . "<br />";
> */
> echo "<tr><td>" .$ex[$j] . "</td><td>" . $res[0] . "</td> </td><td>" .$res[1] . "</td></tr>" ;
> 	}
> 	$j +=21;
> 	$k +=21;
> 	
> 	
> }
>
>
> echo "</table></center>";
>
> mysql_close();
> ?>
>

A couple of other things.  First of all, the mysql_xxx functions are 
deprecated and will eventually disappear.  You should use the newer 
mysqli_xxx() functions.  Most are similar to the mysql_xxx() functions, 
but mysqli_xxx() also provides additional options.

Also, you can get all of the MAC addresses in your arp table at once 
with one query, i.e.

SELECT x,y.z
FROM table
WHERE value in ('val1', 'val2', val3');

It will take a bit of work to build the list of mac addresses, so it's 
probably something you should wait for later.  But it will be much more 
efficient, as you'll only make one call to the database and allow it to 
do the searching for you.

But the main question here is - what is the output of your arp -a command?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11988

Fromjalaf28@gmail.com
Date2013-11-25 21:32 -0800
Message-ID<21f0bca3-e03b-4bb0-92a2-8603e45606b4@googlegroups.com>
In reply to#11915
Thanks All 

It works i apply your Suggestions 

and i use this ARP command on window's 7

the output of the command "arp -a" is

Interface: 192.168.x.x --- 0xb
  Internet Address      Physical Address      Type
  192.168.x.x           XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.x           XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.x           XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.x           XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.x           XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.xa          XX-XX-XX-XX-XX-XX     dynamic   
  192.168.x.xxx         XX-XX-XX-XX-XX-XX     static    


These Are list of Ip And the Mac Address of the Lan Its Daynamic Not Static.And  the Mac address and the System names are stored in the database.in that problem it will take the physical addrss [ from arp] and match with the database [mac_id column]  and return the System name.

and the Out put of the  Programm  will be Lie This....

  IP Address            System Name
192.168.x.x             Server1
192.168.x.x             Client1 
192.168.x.x             Client2 
192.168.x.x             Client3

[toc] | [prev] | [next] | [standalone]


#11989

Fromjalaf28@gmail.com
Date2013-11-25 21:41 -0800
Message-ID<2ca0dc82-85a2-4e57-b6b8-ada747640289@googlegroups.com>
In reply to#11915
It works but it show's the Ip and MAc address only IP less then 10.for example

it shows 192.168.xx.9
but after 192.168.xx.11 it not show 

[toc] | [prev] | [next] | [standalone]


#11990

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-26 07:20 -0500
Message-ID<l723lj$ugf$2@dont-email.me>
In reply to#11989
On 11/26/2013 12:41 AM, jalaf28@gmail.com wrote:
> It works but it show's the Ip and MAc address only IP less then 10.for example
>
> it shows 192.168.xx.9
> but after 192.168.xx.11 it not show
>

You don't show your code, so it's impossible for us to help you find 
your problem.

One basic rule.  If you're having problems with a piece of code, you 
need to post the failing code for others to see.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11994

Fromjalaf28@gmail.com
Date2013-11-26 21:22 -0800
Message-ID<b9bfb809-4513-4262-a0c9-65acf113aa43@googlegroups.com>
In reply to#11990
Hi Jerry 

i already Post It 
but now i m post it again..

here is the Code..


<?php

$out=shell_exec("arp -a");

$ex=explode(" ",$out);

$j=21;
$k=32;

$ln=@mysql_connect("localhost","root","");

if(!$ln)
{
	die("Could not Connect to The Server");
}

mysql_select_db("mysql") or die("Could Not Connect with database");

$rs=mysql_query("select * from mac_add");



while($rr=mysql_fetch_array($rs))
{
	$rsr=mysql_query("select * from mac_add where mac_id= '$ex[$k]'");
	while( $res=mysql_fetch_array($rsr))
	{

	echo "<tr><td>" .  htmlspecialchars($ex[$j]) . "</td><td>" .  htmlspecialchars($res[0]) . "</td> </td><td>" . htmlspecialchars($res[1]) . "</td></tr>" ;
	
	}
	
	$j +=21;
	$k +=21;
		
}


echo "</table></center>";

mysql_close();

?>

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web