Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Grok 🤖

Members
  • Posts

    24
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Grok 🤖's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. oh damnit, im very sorry.... the fact I didnt sleep last night pretty much says it all! thanks again!
  2. Thankyou very much for the reply but im afraid with that code the page now fails to load, not really sure why as im not really adept with xpath or XML in general to be honest, hehe I have been removing parts to try and find out which line is causing the problem and I cant even get the page to load with only this part in foreach ($discovery->xpath("//host[status/@state='up']") as $ndiscovery) { } endforeach;
  3. The XML in question is there on the post, the full XML file is way too large to post up. edit: or if you are asking what the XML data actually is then its output from a linux program called nmap... it is a network discovery application showing ip addresses, mac addresses, open ports etc etc.
  4. Hi everyone, I was wondering if anybody could help me with some XML parsing.... I have managed to parse most of the XML into variables but im struggling with one of the nodes where it is a second child : node[1] here is a snippet of the tree ($ndiscovery) SimpleXMLElement Object ( [@attributes] => Array ( [starttime] => 1350215881 [endtime] => 1350215891 ) [status] => SimpleXMLElement Object ( [@attributes] => Array ( [state] => up [reason] => arp-response ) ) [address] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [addr] => 192.168.0.1 [addrtype] => ipv4 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [addr] => A0:21:B7:06:20:67 [addrtype] => mac ) ) ) and a snippet of my code to parse ( where the problem seems to arise ) $discovery = simplexml_load_file('discovery.xml') foreach ($discovery->host as $ndiscovery) if ($ndiscovery->status->attributes()->state == up) { $inum++; $ip[$ipnum]=$ndiscovery->address[0]->attributes()->addr; $mac[$ipnum]=$ndiscovery->address[1]->attributes()->addr; etc... etc... if I remove the $mac line everything is fine, but if I leave it in there it seems to stop the rest of the webpage executing (after the php code finishes) the $mac line does actually work for retrieving the node but it seems to stop the rest of the page executing, very confused at this point. I had to use the [1] because there are 2 node's that are named the same (addr) Anybody have any ideas? thanks very much
  5. derwert, thanks again. I did read your post and your right, I probably should go down the XML route, thanks for reminding me of that output functionality. On the other hand though I had been working on the regular expression for quite a while and was mostly wanting to learn how you could do it with that method for future programming/regular expression needs, and also it was bugging me! hehe. But anyway, thanks for all the help. Im starting to understand regular expressions but will go down the XML route!
  6. Hi derwert, thanks for the reply..... I have managed to get so far with this problem. I am able to get the information I need into array's but one problem now exists. When I do my nmap scan it does not return the mac address for my local machine, which means my IP and mac array's become out of sync because one of the mac addresses are not stored meaning the mac array is one number behind the ip array ( when it gets to the point where my local machine does not return the mac address ). This is what I have tried: $string = shell_exec ('sudo nmap -sP 192.168.0.0/24'); preg_match_all("/\d{1,3{\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $ip); preg_match_all("/((?:[0-9a-f]{2}[:-]{5}[0-9a-f]{2})/i", $string, $mac); print_r($ip); print_r($mac); I get the following arrays out. p.s. I have no idea why it prints the mac array out twice but I dont think that should be a problem. But anyway, as you can see im missing the mac address for 0.8 so my ip and mac arrays are out of sync ie. ip[2] does not refer to mac[2] Array ( [0] => Array ( [0] => 192.168.0.1 [1] => 192.168.0.2 [2] => 192.168.0.8 ) ) Array ( [0] => Array ( [0] => A0:21:B7:06:20:67 [1] => 00:01:29:A4:47:F2 ) [1] => Array ( [0] => A0:21:B7:06:20:67 [1] => 00:01:29:A4:47:F2 )i
  7. What about parsing these bold sections into variables... The string can and will change though, depending upon how many host's nmap picks up ( 4 in this case ) and also like in this example the last mac address for 192.168.0.8 was not picked up, but I would need a blank entry for that array so that the ip and mac array numbers correspond. I dont expect an answer, im willing to research and try to figure things out for myself but pointing me in the right direction would be great. for example: $IP[0] = "192.168.0.1" $IP[1] = "192.168.0.2" $IP[2] = "192.168.0.4" $IP[3] = "192.168.0.8" $MAC[0] = "00:00:00:00:00:01" $MAC[1] = "00:00:00:00:00:02" $MAC[2] = "00:00:00:00:00:03" $MAC[3] = " " Starting Nmap 5.21 ( http://nmap.org ) at 2012-10-10 20:53 BST Nmap scan report for 192.168.0.1 Host is up (0.0055s latency). MAC Address: 00:00:00:00:00:01 (Unknown) Nmap scan report for 192.168.0.2 Host is up (0.00019s latency). MAC Address: 00:00:00:00:00:02 (DFI) Nmap scan report for 192.168.0.4 Host is up (0.0043s latency). MAC Address: 00:00:00:00:00:03 (Unknown) Nmap scan report for 192.168.0.8 Host is up. Nmap done: 256 IP addresses (4 hosts up) scanned in 5.37 seconds
  8. yeah just thought of that, thanks alot
  9. The only problem I have now is that some of the switches contain two -- characters such as " --state " and I seem to be having problems using the likes of : echo "$parsedarray[-state]";
  10. edit: got it thanks
  11. yes I have managed to get the array printed out with the correct entries. Just need to call them in the appropriate table cells now. Thanks guys
  12. thanks very much for the reply, im not entirely sure how this code works but I will try it. Will this also work if the string has more switches? and I assume I just call these variables with $args[A] etc?
  13. hi guys, ive spent a good amount of time researching how to parse linux iptables rules into seperate variables so I can use each variable inside appropriate cells inside a table, but without any luck . For example, a possible string could be: $string = "-A INPUT -s 192.168.0.1 -p TCP -j DROP" I want to be able to put: "192.168.0.1" into a $source variable "TCP" into a $protocol variable "DROP" into a $jump variable I was thinking about doing an explode splitting each word up using the "space" and then doing if $explode[2] = "-s" then $source = $explode[3] type thing but I would have to check for each available switch on every array number (if you know what I mean). Is there a more efficient way of doing this?
  14. hi guys, another little problem I am trying to display a list of information inserted into the database in DESC order, but only want to display 20 row's and then a section where the user can go back or forward a page on to the previous 20 or the next 20, if that makes any sense. I got it working to a certain extent by messing around with different things but it would not display the very last stuff on the 1st page but on the 2nd, or also with different code I had it display the newest additions on the first page but in reverse order. Here is my current code mysql_connect("localhost","forum","forum") or die(mysql_error()); mysql_select_db("forum") or die(mysql_error()); $genree = $_GET['genre']; $currentpage = $_GET['page']; $currentpage0 = ($currentpage - 1); $currentpage2 = ($currentpage + 1); $query = mysql_query("SELECT MAX(id) AS maximum FROM mixes"); list ($maxid1) = mysql_fetch_row($query); $maxid2 = (20*$currentpage); $maxid3 = $maxid2 - 20; if ($currentpage == 1) { $maxid2 = 20; $maxid3 = 0; } var_dump ($maxid3); var_dump ($maxid2); //query the db $getmixes = mysql_query("SELECT * FROM mixes WHERE genre='$genree' AND id >= '$maxid3' AND id <= '$maxid2' ORDER by id DESC") or die(mysql_query()); $i = 1; while ($row = mysql_fetch_assoc($getmixes)) { $mixtitle = $row['title']; $id = $row['id']; $poster = $row['poster']; $url = $row['url']; echo "<a href='$url'>$mixtitle"; echo "<br>"; if ($i >= 19) break; $i++; } $genree = $_GET['genre']; $currentpage = $_GET['page']; ?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage0 ?>"><</a><?php echo " page $currentpage ";?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage2 ?>">></a><?php; so what the above currently does is on page 1 displays ID 0-20, page 2 displays ID 20-40 which is kind of right but not quite, I want it display the last ID at the top of page 1 and the very first addition on the last page at the bottom. I was playing around with finding the max ID in the database and then attempting to work out which id chunk that it should output but that got messy. I know im probably doing this the wrong way but im new to PHP and still trying to learn the better methods of doing such things, what would be a good way to do what I require? thanks for your time and help!
  15. and then quoting my code? You never mentioned isset()? And you are wrong, no, Booleans are True/False, wether a variable is set or not is entirely different, a variable with no data can return false. Thus, in fact, the only way to check if a variable exists (post data with no data), use isset(), as i said before. Would like to know .. what are you on about? -------------- Jason; Maybe you need to rethink the general structure of your script. It should be something like: If(Session Exists){ // Continue to load page normally }else{ // Show log in page } To make it easier to understand you can use a function checkbbsession() that you make yourself that will check wether the person is logged in or not. and should return true or false respectively. You should also indent your code to make it easier to read and debug mistakes. Also, Oni-Kun, the Session if statement is already outside of the POST check statement? -CB- -CB- Thanks for the help at the moment the page seems to be displaying properly, but I just cant get logged in due to this wrong password thing, once that works I will be able to see if the welcome is displayed properly and if not I will change the structure as you recommended It seems like the hash check function supplied with phpbb is not comparing the hashes properly? When i type in a wrong username it says user does not exist, and when I type in the correct password it says wrong password
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.