Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help| Unique continer or special IP's from list #78

Open
z3ro opened this issue Dec 11, 2023 · 0 comments
Open

Help| Unique continer or special IP's from list #78

z3ro opened this issue Dec 11, 2023 · 0 comments

Comments

@z3ro
Copy link

z3ro commented Dec 11, 2023

Hello,
i have a list of IP's i want to pull out only the unique IP's (blocks) from the list.
For example, 192.168.0.0/32 is in 192.168.0.0/24 so it should just print the container 192.168.0.0/24 and the rest containers like ( 192.148.0.1/8 which include 192.148.0.1/9 ) and the rest of unique blocks.

My code like this, i was straggling with no correct results. thanks for

`
$array1 = array('192.168.0.0/32', '192.148.0.1/8', '142.158.2.1/23', '192.148.0.1/9', '192.168.1.0/24', '192.168.0.0/24');
$res=[];
foreach($array1 as $key=> $blockx){

foreach($array1 as  $key2=> $blocky){
	$block = IPBlock::create($blockx);
	$check = $block->contains($blocky);
	if(!$check){
		if(count($res)==0){
			//echo $blockx .":".$blocky.":".$check."\n";
			//if(!in_array($blocky,$res)){
			$res[]=$blocky;
			//}
		}
		foreach($res as   $blockz){
			
			$block = IPBlock::create($blocky);
			$check = $block->contains($blockz);
			if(!$check){
			foreach($res as $keyxx =>  $blockz){
				$block = IPBlock::create($blockz);
				$check = $block->contains($blocky);
				if(!$check){
					if(!in_array($blocky,$res)){
				$res[]=$blocky;
				}else{
					unset($res[$keyxx]);
					if(!in_array($blocky,$res)){
					$res[]=$blocky;
					}
				}
				}
			}
				
			}else{
				foreach($res as  $keyz=> $blockz){
				$block = IPBlock::create($blockz);
				$check = $block->contains($blocky);
				if(!$check){
					if(!in_array($blocky,$res)){
				$res[]=$blocky;
				}else{
					unset($res[$keyz]);
					if(!in_array($blocky,$res)){
					$res[]=$blocky;
					}
				}
				}
			}
			}
		}
	}

}

}
print_r($res);`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant