• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting IPs of all the remote machines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting IPs of all the remote machines


  • Subject: Getting IPs of all the remote machines
  • From: Lorenzo <email@hidden>
  • Date: Sat, 26 Apr 2003 11:33:36 +0200

Hi,
I would like to say Thanks to Charles Srstka, Mark Dalrymple, Tom Sutcliffe,
Finlay Dobbie who helped me to build the following routine.
I would like to share it, maybe someone could like to know this technic.


// This routine asks the shell to execute a general unix string command and
// takes the result through a pipeline. The specific routine here below
// returns a list of the IPs of all the remote machines connected to the
// local machine. (currentHostIPAddress is the IP of the local machine.)


NSString *currentHostIPAddress = [[NSHost currentHost] address];
NSString *commandLine = [NSString stringWithFormat:@"netstat -f inet -n |
grep '%@' | grep ESTABLISHED | awk '{ print $5 }'", currentHostIPAddress];
NSArray *args = [NSArray arrayWithObjects:@"-c", commandLine, nil];

NSLog(@"currentHostIPAddress: %@", currentHostIPAddress);

NSTask *task = [[NSTask alloc] init];
NSPipe *thePipe = [NSPipe pipe];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:args];
[task setStandardOutput:thePipe];
[task launch];
[task waitUntilExit];

if([task terminationStatus] != noErr){
[task release];
NSLog(@"Error from the shell.");
return;
}

NSData *dataOut = [[[task standardOutput] fileHandleForReading]
availableData];

if(dataOut){
NSString *theIDList = [[NSString alloc] initWithData:dataOut
encoding:NSASCIIStringEncoding];
NSLog(@"The output of netstat is: %@", theIDList);
[theIDList release];
}
else NSLog(@"The output of netstat is NULL");
[task release];




Best Regards
--
Lorenzo
email: email@hidden

- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Multithreading with DO and Notifications
  • Next by Date: Re: Multithreading with DO and Notifications
  • Previous by thread: Re: Multithreading with DO and Notifications
  • Next by thread: subclassing NSColorWell
  • Index(es):
    • Date
    • Thread