adobe air monitor network interface

how do i monitor network interface in adobe air.

after retrieve the list from network interface i wanna know that is active or inactive. if i try to unplug my (example: router)  it should be changed to inactive and if i plug back it will change it to active. how to do.


please help, experts. urgent urgent
aaronyeo22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgofmanCommented:
You can use Network monitor


import air.net.URLMonitor;

private var monitor: URLMonitor;


private var networkAvailable:Boolean = false;
private function checkNetworkConnection():void{
     monitor = new URLMonitor(new URLRequest("http://www.google.com") );
     monitor.addEventListener(StatusEvent.STATUS, announceStatus);
     monitor.start();
}


private function announceStatus(e:StatusEvent):void {
    trace("Status change. Current status: " + monitor.available);
     if(monitor.available) {
          networkAvailable = true;
          init();
      }else{
          networkAvailable = false;
}

}

0
aaronyeo22Author Commented:
your example I understand and that's not what I want.  I want the program able to detect if my ( example router )was unplug that network interface status is inactive and  I plug back the status change to active. How to do it. Thanks
0
dgofmanCommented:
Change monitor = new URLMonitor(new URLRequest("http://www.google.com") );

to your router IP address

for example

monitor = new URLMonitor(new URLRequest("192.168.1.1") );
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

aaronyeo22Author Commented:
Sorry. It cannot. I test it already. Any alternative. Thanks
0
dgofmanCommented:
Please tell me what you are expecting and what result did you get?
0
aaronyeo22Author Commented:
private var monitor:URLMonitor;
                  
                  protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                  {
                        monitor = new URLMonitor(new URLRequest("192.168.0.1"));
                        monitor.addEventListener(StatusEvent.STATUS, handle_status);
                        monitor.start();
                  }
                  
                  private function handle_status(event:StatusEvent):void{
                        connectedImage.source = monitor.available ? green : red;      
                  }
<s:Image id="connectedImage" source="{red}"/>

the above sample i was tested it when i try to unplug it still display green light
0
aaronyeo22Author Commented:

                        var results:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
                        for (var k:int=0; k<results.length; k++)
                        {
                  
                                  Alert.show("Name: " + results[k].name + "\n"
                                    + "DisplayName: " + results[k].displayName + "\n"
                                    + "MTU: " + results[k].mtu + "\n"
                                    + "HardwareAddr: " + results[k].hardwareAddress + "\n"
                                    + "Active: " + results[k].active + "\n" );  
            
                              for (var j:int=0; j<results[k].addresses.length; j++)
                              {
            
                                     Alert.show("Addr: " + results[k].addresses[j].address + "\n"
                                          + "Broadcast: " + results[k].addresses[j].broadcast + "\n"
                                          + "PrefixLength: " + results[k].addresses[j].prefixLength + "\n"
                                          + "IPVersion: " + results[k].addresses[j].ipVersion + "\n");  
                              }
                        
                        }

the above code i am to detect the router whether plug or unplug. unfortunately is not live. i need to refresh just can obtain the router active or inactive. how do i use the "monitor.start();" functions.
0
dgofmanCommented:
aaronyeo22:
This code working fine. The only problem you may get if you have multiple network cards or wireless access.
For example I have line and wireless switch if I disconnected wireless access the event handler will not get call until I will not unplug-in a network cable. As soon as I will disconnect all my network devices my status will change

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx" 
					   creationComplete="creationCompleteHandler()">
	<fx:Script>
		<![CDATA[
			import air.net.URLMonitor;
			
			import mx.controls.Alert;

			private var monitor:URLMonitor;
			
			protected function creationCompleteHandler():void
			{
				monitor = null;
				monitor = new URLMonitor(new URLRequest("http://www.google.com"));
				//monitor.pollInterval = 500;
				monitor.addEventListener(StatusEvent.STATUS, handle_status);
				monitor.start();

			}
			
			private function handle_status(event:StatusEvent):void{
				var results:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces(); 
				for (var k:int=0; k<results.length; k++) 
				{ 
					
					trace("Name: " + results[k].name + "\n" 
						+ "DisplayName: " + results[k].displayName + "\n" 
						+ "MTU: " + results[k].mtu + "\n" 
						+ "HardwareAddr: " + results[k].hardwareAddress + "\n" 
						+ "Active: " + results[k].active + "\n" );   
					
					for (var j:int=0; j<results[k].addresses.length; j++) 
					{ 
						
						trace("Addr: " + results[k].addresses[j].address + "\n" 
							+ "Broadcast: " + results[k].addresses[j].broadcast + "\n" 
							+ "PrefixLength: " + results[k].addresses[j].prefixLength + "\n" 
							+ "IPVersion: " + results[k].addresses[j].ipVersion + "\n");   
					} 
					
				} 

				connectedBox.setStyle("backgroundColor", monitor.available ? "green" : "red");
			}
		]]>
	</fx:Script>
	
	<mx:HBox id="connectedBox" width="20" height="20"/>
</s:WindowedApplication>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aaronyeo22Author Commented:
thanks of the sample codes. if google active and definitely the light become green and how about google website down. So, i dont want the new URLRequest of google.com. i want specific to the network interface like my router or local network connection. thanks.
0
dgofmanCommented:
aaronyeo22:
You are kidding if google.com will be down US economy will be crashed, in that time no body will care about your network monitor :)

0
aaronyeo22Author Commented:
that is not a total solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.