Faster way to check for server at a plarticular port?

I am trying to check all the servers running at a particular port in my network using java/Android. The method I'm using currently takes 5-10 mins to do this.Is there any faster way?

I am new to socket programming, So any help will be highly appreciated.

public void findservers()//throws UnknownHostException, SocketException { Enumeration e = null; try { e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); } //Data dt = new Data(); //Client cl = new Client(); //dt.setClientObject(cl); while(e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); String ip = i.getHostAddress(); System.out.println(ip); String sip = ip.substring(0, ip.indexOf('.',ip.indexOf('.',ip.indexOf('.')+1) + 1) + 1); System.out.println(sip); try { for(int it=1;it<=255;it++) { String sip1 = sip+it; System.out.println(sip1); //InetAddress.getByName(sip1).isReachable(100); //System.out.println(sip1+" is online"); findserver(sip1); //cl.ask(sip); } } catch (Exception e1) { System.out.println(sip); System.out.println("hello"); } } } } public void findserver(String ip) { // String ip = "192.168.43.41"; try { InetAddress ping = InetAddress.getByName(ip); Socket s = new Socket(ping, 50005); System.out.println("Server found on IP: " + ping.getCanonicalHostName()); s.close(); } catch (IOException e) { System.out.println("Nothing much"); System.out.println(e); } }

Category:java Views:3 Time:2017-09-01

Related post

  • Is there a faster way to check for an XML Element in LINQ to XML, and parse a bool? 2010-01-14

    FYI, This is very similar to my last question: Is there a faster way to check for an XML Element in LINQ to XML? Currently I'm using the following extension method that I made to retrieve the bool values of elements using LINQ to XML. It uses Any() t

  • Is there a faster way to check for an XML Element in LINQ to XML, and parse an int? 2010-01-14

    FYI, This is very similar to my last question: Is there a faster way to check for an XML Element in LINQ to XML, and parse a bool? Currently I'm using the following extension method that I made to retrieve the int values of elements using LINQ to XML

  • Fast way to check for the existence of images on a remote server 2010-06-24

    I have a website which loads images from a CDN. I have a requirement to check for the existence of 100s of images on the CDN. I am using this code to achieve this: Protected Function RemoteImageExists(ByVal Path As String) As Boolean Dim httpRequest

  • Is there a faster way to check for an XML Element in LINQ to XML? 2010-01-14

    Currently I'm using the following extension method that I made to retrieve the values of elements using LINQ to XML. It uses Any() to see if there are any elements with the given name, and if there are, it just gets the value. Otherwise, it returns a

  • Faster way to check for element in array? 2011-08-04

    This function does the same as exists does with hashes. I plan on use it a lot. Can it be optimized in some way? my @a = qw/a b c d/; my $ret = array_exists("b", @a); sub array_exists { my ($var, @a) = @_; foreach my $e (@a) { if ($var eq $e) { retur

  • What is the proper way to check for existence of objects in Rails / Ruby? 2011-01-19

    I have a lot of models and relations. Due to this fact, there is lot of calls in views/controllers, which look like this: @object.something.with_something.value Some part of the chain can end up being nil, which is perfectly ok. What is the proper/cl

  • Fast Way To Check Many Bluetooth Devices by MAC Address 2011-11-15

    I'm creating a tool that checks for the presence of many (~100) bluetooth devices. I'll have their MAC addresses already. I just want to know if they're in range, even if not set to discoverable. Using hcitool name <bt_addr> does this. But it's

  • Nullable types: best way to check for null or zero in c# 2009-03-11

    I'm working on a project where i find i'm checking for the following in many, many places: if(item.Rate == 0 || item.Rate == null) { } more as a curiousity than anything, what's the best way to check for both cases? I've added a helper method which i

  • Is there a better way to check for valid values? 2010-12-10

    I have a property in my class that can only be one of several values, what is the best way to limit the input on this property. Here is what I'm doing now, and I'm sure there must be a better way. public void SetValue(int value) { if(value != 1 || va

  • Best way to check for IE less than 9 in JavaScript without library 2011-04-07

    What would be your fastest, shortest (best) way to detect browser which is IE and version less than 9 in JavaScript, without using jQuery or any add-on libraries? --------------Solutions------------- Javascript var ie = (function(){ var undef, v = 3,

  • Fastest way to check for the existence of a specific item in a 30M line text file 2011-11-10

    I'm working with a large dataset that I need to query for the existance of specific items via Ruby. If it helps, imagine a 30M line text file that lists SHA1 values. I'm trying to determine the fastest way of checking for the presence of a specific S

  • Proper way to check for Network Connection in iOS 2011-11-10

    I'm using the Reachability class to monitor network connection and server availability in a couple of iPhone apps. I have the following code in my AppDelegate: // Observe the kNetworkReachabilityChangedNotification. When that notification is posted,

  • Reliable way to check for mobile in C#? 2011-12-26

    This question already has an answer here: How do I detect a mobile browser in a .NET MVC3 application 2 answers I'm building a site in ASP.NET MVC/C#. I base most of my controllers off of a base controller. In that base controller I handle quite a fe

  • Is security compromised if I uncheck "check for server certificate revocation" 2012-08-20

    I am using Vista Home and I use a Magic Jack "Voice Over Intenet Protocol" (VOIP) telephone adapter to make long distance and local phone calls. According to Magic Jack, the only way I can have my phone Contacts and Calls download and show in the Mag

  • Safest way to check for integer 2009-02-24

    This is probally more of an elegance question than functionality. I am looking for the absolutely safest way to check for an integer from a string and an object, Using most of the built in functions for this in .net seem to generate a first chance ex

  • Easy way to check for valid commandline parameters in Perl? 2011-02-16

    I'm looking for an easy way to check for a correct number of command line parameters, displaying a usage message if an error occurs and then immediately exit. I thought of something like if (@ARGV < 3) { print STDERR "Usage: $0 PATTERN [FILE...]\n

  • Fast way to check if file is open on OS X 2011-02-24

    Is there a fast way to check if a file handle is closed from the command line on os x? lsof works, of course, but is super slow. --------------Solutions------------- You´ll probably want to check out the DTrace Family man dtrace. If you´re only inter

  • Faster way to search for a string than the boyer moore algorithm? 2011-07-08

    Is there any faster way to search for a string in a file? --------------Solutions------------- Look at this site, where you can also see the matching time for each of the algorithms. The Turbo Boyer-Moore algorithm is faster, but requires more space.

  • In a social network environment, what would be the easiest way to check for friendships globally? 2011-10-08

    For reference, here is a question on SO that I asked recently that is relevant to this question: How to model Friendship relationships On that question, we figured out a way to display news feed items only if posted by friends. However, what I need i

  • Javascript: fast way to check if form contents have been changed before submission 2011-12-03

    Simple question (I guess)... I'm in an "edit-some-element" html form. As the page load, the form is filled with current element attributes (eg. name, etc.) I could modify some input fields or even decide not to do that but I click the same on submit

  • C faster way to check if a directory exists 2012-02-16

    I'm using opendir function to check if a directory exists. The problem is that I'm using it on a massive loop and it's inflating the ram used by my app. What's the best (faster) way to check if a directory exists in C? What's the best (faster) way to

  • Which is the best way to check for the existence of an attribute? 2012-03-17

    Which is a better way to check for the existence of an attribute? Jarret Hardie provided this answer: if hasattr(a, 'property'): a.property I see that it can also be done this way: if 'property' in a.__dict__: a.property Is one approach typically use

  • Faster way to check intersected rectangles? 2012-03-17

    Except from my Rect-class: public class Rect { public int x; public int y; public int w; public int h; public Rect(int x, int y, int w, int h) { this.x = x; this.y = y; this.w = w; this.h = h; } ... } I have a method to check if two Rects intersects

  • Ways to check for division by zero 2012-04-08

    Possible Duplicate: How to catch a division by zero? Aside from checking if the denominator is 0, are there other ways to check for a division of zero in php? --------------Solutions------------- No, there is no other way to check for division by 0 o

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.125 (s). 11 q(s)