trp Posted April 14, 2010 Share Posted April 14, 2010 Hi guys, I am using Windows Server 2003, Apache and PHP5. I have created a text file using 'nmap' the file looks like this: Host: 192.168.0.1 () Status: Up Host: 192.168.0.2 () Status: Down Host: 192.168.0.3 () Status: Down I am wanting to record ONLY the IP's that have the status of "Up" in a MySQL database. If anyone can help me it would be really great! Thanks, TRP Link to comment https://forums.phpfreaks.com/topic/198529-sorting-a-file/ Share on other sites More sharing options...
ChemicalBliss Posted April 14, 2010 Share Posted April 14, 2010 I'd suggest oen step at a time, lets get this file into an array, one we can go through: use file() it returns an array of lines. then it is a very simple substr comparison: substr($line,-1) == "p" ... then if thats true, add it to a new array $newarray[] = $line; now you can do some advance stuff with the lines you wanted.. -cb- Link to comment https://forums.phpfreaks.com/topic/198529-sorting-a-file/#findComment-1041775 Share on other sites More sharing options...
xt3mp0r~ Posted April 14, 2010 Share Posted April 14, 2010 Assuming you saved output from nmap to nmap.txt .. you can use below code to get the ip into $ip variable and then store it in mysql db, if you want. <?php $lines = file('nmap.txt'); foreach($lines as $line) { if(strpos($line,"Up") !== false) { preg_match('/Host: (.*?) ()/',$line,$ip); $ip = $ip[1]; echo $ip; } } ?> Link to comment https://forums.phpfreaks.com/topic/198529-sorting-a-file/#findComment-1041840 Share on other sites More sharing options...
trp Posted April 14, 2010 Author Share Posted April 14, 2010 That is awesome, really helpful!! Thanks so much for the fast reply and brilliant help TRP Link to comment https://forums.phpfreaks.com/topic/198529-sorting-a-file/#findComment-1041928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.