MCPcopy Create free account
hub / github.com/bit4woo/burp-api-common / ipset2cidr

Method ipset2cidr

src/main/java/burp/IPAddressUtils.java:169–204  ·  view source on GitHub ↗
(Set<String> IPSet)

Source from the content-addressed store, hash-verified

167 To get a smaller network with a set of IP addresses
168 */
169 private static String ipset2cidr(Set<String> IPSet) {
170 try {
171 if (IPSet == null || IPSet.size() <=0){
172 return null;
173 }
174 if (IPSet.size() ==1){
175 return IPSet.toArray(new String[0])[0];
176 }
177 List<String> list = new ArrayList<String>(IPSet);
178 SubnetUtils oldsamllerNetwork =new SubnetUtils(list.get(0).trim()+"/24");
179 for (int mask=24;mask<=32;mask++){
180 //System.out.println(mask);
181 SubnetUtils samllerNetwork = new SubnetUtils(list.get(0).trim()+"/"+mask);
182 for (String ip:IPSet) {
183 ip = ipClean(ip);
184 if (!isValidIP(ip)) {
185 System.out.println(ip + "invalid IP address, skip to handle it!");
186 continue;
187 }
188 if (samllerNetwork.getInfo().isInRange(ip) || samllerNetwork.getInfo().getBroadcastAddress().equals(ip.trim()) || samllerNetwork.getInfo().getNetworkAddress().equals(ip.trim())){
189 //52.74.179.0 ---sometimes .0 address is a real address.
190 continue;
191 }
192 else {
193 String networkaddress = oldsamllerNetwork.getInfo().getNetworkAddress();
194 String tmpmask = oldsamllerNetwork.getInfo().getNetmask();
195 return new SubnetUtils(networkaddress,tmpmask).getInfo().getCidrSignature();
196 }
197 }
198 oldsamllerNetwork = samllerNetwork;
199 }
200 return null;
201 }catch (Exception e) {
202 throw e;
203 }
204 }
205
206 public static String ipClean(String ip){
207 ip = ip.trim();

Callers 1

toSmallerSubNetsMethod · 0.95

Calls 2

ipCleanMethod · 0.95
isValidIPMethod · 0.95

Tested by

no test coverage detected