Adobe
Products
Creative Suite
Photoshop Family
Acrobat Family
Flash Platform
Digital Marketing Suite
Digital Publishing Suite
More products
Solutions
Digital marketing solutions
Digital media solutions
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Store
Adobe Store for home and home office
Education Store for students, educators, and staff
Business Store for small and medium businesses
Other ways to buy
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections   Search  
Solutions Company
Help Learning
Sign in Welcome, My orders My Adobe
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Retrieving a list of network interfaces in Adobe AIR 2

by William Liang

William Liang

Modified

10 June 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR Flex networking

Requirements

Prerequisite knowledge

This article is intended for developers who are comfortable with ActionScript and who have a basic understanding of networking.

User Level

All

Required products

  • Adobe AIR

Among the new networking features introduced in Adobe AIR 2 is the ability to enumerate all hardware and software network interfaces. This list of network interfaces includes information about each interface such as IP address, MAC address, status, and more.

This article describes the new NetworkInfo class and the information it provides; you can use this information to implement peer-to-peer features and advanced networking applications.

NetworkInfo use cases and class overview

Enumerating all hardware and software network interfaces reveals detailed information about the networking capabilities of the local machine. This information is required for many advanced networking features. For example, peer-to-peer and Voice-over-IP (VoIP) applications frequently need to be able to traverse Network Address Translation (NAT) gateways. In order to traverse a NAT, an application typically needs the list of available network interfaces. The application can then probe each interface to determine if it can be used to traverse the NAT and establish a connection with a remote client.

Peer-to-peer applications often also need to obtain a list of available interfaces and their capabilities. For example, when a Session Initiation Protocol (SIP) client wants to establish a connection with another SIP client, the two clients need to exchange their capabilities. These capabilities include the networking capabilities of the local machine and the networking between them.

In AIR 2, you can now incorporate network information within your application, so you can implement standard networking or peer-to-peer features, such as the ones listed above, or develop new ones.

NetworkInfo class overview

The new NetworkInfo class is analogous to ipconfig on Windows and ifconfig on Mac OS X or Linux. NetworkInfo returns a list of network interfaces and the following information for each interface:

  • Name
  • Display name
  • MTU
  • Hardware address (or MAC address)
  • Active (or status)
  • Address (or IP address)
  • Broadcast address
  • Prefix length
  • IP version (or IP Family)

Using the NetworkInfo class

NetworkInfo is a singleton class. The code below is a simple example of how to use it to display information about the local machine's network interfaces.

import flash.net.NetworkInfo; public function findInterface():void { var results:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces(); for (var i:int=0; i<results.length; i++) { var output = output + "Name: " + results[i].name + "\n" + "DisplayName: " + results[i].displayName + "\n" + "MTU: " + results[i].mtu + "\n" + "HardwareAddr: " + results[i].hardwareAddress + "\n" + "Active: " + results[i].active + "\n"; for (var j:int=0; j<results[i].addresses.length; j++) { output = output + "Addr: " + results[i].addresses[j].address + "\n" + "Broadcast: " + results[i].addresses[j].broadcast + "\n" + "PrefixLength: " + results[i].addresses[j].prefixLength + "\n" + "IPVersion: " + results[i].addresses[j].ipVersion + "\n"; } output = output + "\n"; } }

If you run this example on an Apple MacBook Pro, you will get a list of interfaces that minimally contains en0 and en1; for example:

Name: en0 DisplayName: MTU: 1500 HardwareAddr: 00:25:00:a5:35:1e Active: true Addr: 2001:1890:110b:1498:225:ff:fea5:351e Broadcast: PrefixLength: 64 IPVersion: IPv6 Addr: 153.32.154.241 Broadcast: 153.32.155.255 PrefixLength: 22 IPVersion: IPv4 Name: en1 DisplayName: MTU: 1500 HardwareAddr: 00:23:6c:96:ab:c1 Active: true Addr: 10.4.217.218 Broadcast: 10.4.219.255 PrefixLength: 22 IPVersion: IPv4

The network change event

Another useful feature of the NetworkInfo class is the ability to detect network changes. A network change event occurs when a network interface becomes enabled or disabled.

For example, an application may use the NetworkInfo class to obtain a list of currently available network interfaces and select the best candidate interface from that list. Later, if another interface becomes enabled, the application will be notified via a network change event. It can then use that opportunity to determine if the recently enabled interface is a better candidate and reestablish the network connection using the new interface.

Similarly, if an interface becomes disabled or disconnected from the network, the application will receive a network change event, enabling it to take the appropriate action. For example, it may terminate the connection or select another interface and reestablish the connection.

The network change event is fired from the NativeApplication class and bubbled up by the NetworkInfo class. To receive network change events, an application must add an event listener:

NetworkInfo.networkInfo.addEventListener(Event.NETWORK_CHANGE, onNetworkChange);

Alternatively, you can add the event listener on your NativeApplication object:

NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChange);

Where to go from here

For further information about the NetworkInfo class and its usage, please refer to the AIR 2 release notes.

More Like This

  • Using the Adobe AIR 2 NativeProcess API to create a screen recorder
  • Customer story: AIR - NASDAQ Market Replay
  • Using the Salesbuilder Adobe AIR sample application
  • Creating a socket server in Adobe AIR 2
  • User experience considerations with SQLite operations
  • Exploring the new file capabilities in Adobe AIR 2
  • Reducing CPU usage in Adobe AIR
  • Building multilingual Flex applications on Adobe AIR
  • Building an XML viewer on Adobe AIR with Flex
  • Resolving DNS records in Adobe AIR 2

Tutorials & Samples

Tutorials

  • Retrieving a list of network interfaces in Adobe AIR 2
  • Using the AIR 2 NativeProcess API to create a screen recorder
  • Writing multiscreen AIR apps
  • Resolving DNS records in Adobe AIR 2

Samples

  • Using the Salesbuilder Adobe AIR sample application

Adobe AIR Forums

More
02/08/2012 CS5.5 - AIR 3.1 - iPhone debugging
02/07/2012 FacebookMobile - logout user?
02/07/2012 Do app updates delete LSOs?
02/02/2012 Facebook iOS?

Adobe AIR Blog

More
02/02/2012 AIRKinect Extension is a Native Extension for use with Adobe AIR...
02/01/2012 Microsoft Kinect and Adobe AIR
02/01/2012 New Adobe Flash Player 11.2 beta for Desktops and Adobe AIR 3.2 beta
01/30/2012 Using charts inside Mobile Applications with Adobe AIR

Products

  • Creative Suite
  • Photoshop Family
  • Acrobat Family
  • Flash Platform
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Mobile apps

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • Adobe Store
  • For students and educators
  • For small and medium businesses
  • For enterprises
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Pacific - English
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).

Ad Choices

Reviewed by TRUSTe: site privacy statement