MCPcopy Index your code
hub / github.com/cSploit/android / isPortAvailable

Method isPortAvailable

cSploit/src/org/csploit/android/core/System.java:700–734  ·  view source on GitHub ↗
(int port)

Source from the content-addressed store, hash-verified

698 }
699
700 public static boolean isPortAvailable(int port){
701 boolean available = true;
702
703 int available_code = mOpenPorts.get(port);
704
705 if(available_code != 0)
706 return available_code != 1;
707
708 try{
709 // attempt 3 times since proxy and server could be still releasing
710 // their ports
711 for(int i = 0; i < 3; i++){
712 Socket channel = new Socket();
713 InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(mNetwork.getLocalAddressAsString()), port);
714
715 channel.connect(address, 200);
716
717 available = !channel.isConnected();
718
719 channel.close();
720
721 if(available)
722 break;
723
724 Thread.sleep(200);
725 }
726 }
727 catch(Exception e){
728 available = true;
729 }
730
731 mOpenPorts.put(port, available ? 2 : 1);
732
733 return available;
734 }
735
736 public static ArrayList<String> getAvailableSessionFiles(){
737 ArrayList<String> files = new ArrayList<String>();

Callers 2

doInBackgroundMethod · 0.95

Calls 4

getMethod · 0.80
connectMethod · 0.45
isConnectedMethod · 0.45

Tested by

no test coverage detected