1# Network Connection Management 2 3 4> **NOTE**<br> 5> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 6 7## Modules to Import 8 9```javascript 10import connection from '@ohos.net.connection' 11``` 12 13## connection.getDefaultNet 14 15getDefaultNet(callback: AsyncCallback\<NetHandle>): void 16 17Obtains the default active data network. This API uses an asynchronous callback to return the result. 18 19**Required permission**: ohos.permission.GET_NETWORK_INFO 20 21**System capability**: SystemCapability.Communication.NetManager.Core 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| -------- | --------------------------------------- | ---- | ---------- | 27| callback | AsyncCallback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result.| 28 29**Example** 30 31```javascript 32connection.getDefaultNet(function (error, netHandle) { 33 console.log(JSON.stringify(error)) 34 console.log(JSON.stringify(netHandle)) 35}) 36``` 37 38## connection.getDefaultNet 39 40getDefaultNet(): Promise\<NetHandle> 41 42Obtains the default active data network. This API uses a promise to return the result. 43 44**Required permission**: ohos.permission.GET_NETWORK_INFO 45 46**System capability**: SystemCapability.Communication.NetManager.Core 47 48**Return Value** 49 50| Type | Description | 51| --------------------------------- | ------------------------------------- | 52| Promise\<[NetHandle](#nethandle)> | Promise used to return the result.| 53 54**Example** 55 56```javascript 57connection.getDefaultNet().then(function (netHandle) { 58 console.log(JSON.stringify(netHandle)) 59}) 60``` 61 62## connection.hasDefaultNet 63 64hasDefaultNet(callback: AsyncCallback\<boolean>): void 65 66Checks whether the default data network is activated. This API uses an asynchronous callback to return the result. 67 68**System capability**: SystemCapability.Communication.NetManager.Core 69 70**Parameters** 71 72| Name | Type | Mandatory| Description | 73| -------- | ----------------------- | ---- | -------------------------------------- | 74| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** indicates that the default data network is activated.| 75 76**Example** 77 78```javascript 79connection.hasDefaultNet(function (error, has) { 80 console.log(JSON.stringify(error)) 81 console.log(has) 82}) 83``` 84 85## connection.hasDefaultNet 86 87hasDefaultNet(): Promise\<boolean> 88 89Checks whether the default data network is activated. This API uses a promise to return the result. 90 91**System capability**: SystemCapability.Communication.NetManager.Core 92 93**Return Value** 94 95| Type | Description | 96| ----------------- | ----------------------------------------------- | 97| Promise\<boolean> | Promise used to return the result. The value **true** indicates that the default data network is activated.| 98 99**Example** 100 101```javascript 102connection.hasDefaultNet().then(function (has) { 103 console.log(has) 104}) 105``` 106 107## connection.getAllNets 108 109getAllNets(callback: AsyncCallback<Array<NetHandle>>): void 110 111Obtains the list of all active data networks. This API uses an asynchronous callback to return the result. 112 113**Required permission**: ohos.permission.GET_NETWORK_INFO 114 115**System capability**: SystemCapability.Communication.NetManager.Core 116 117**Parameters** 118| Name| Type| Mandatory| Description| 119| -------- | -------- | -------- | -------- | 120| callback | AsyncCallback<Array<[NetHandle](#nethandle)>> | Yes| Callback used to return the result.| 121 122**Example** 123 124``` 125connection.getAllNets(function (error, nets) { 126 console.log(JSON.stringify(error)) 127 console.log(JSON.stringify(nets)) 128}); 129``` 130 131 132## connection.getAllNets 133 134getAllNets(): Promise<Array<NetHandle>> 135 136Obtains the list of all active data networks. This API uses a promise to return the result. 137 138**Required permission**: ohos.permission.GET_NETWORK_INFO 139 140**System capability**: SystemCapability.Communication.NetManager.Core 141 142**Return Value** 143| Type| Description| 144| -------- | -------- | 145| Promise<Array<[NetHandle](#nethandle)>> | Promise used to return the result.| 146 147**Example** 148 149``` 150connection.getAllNets().then(function (nets) { 151 console.log(JSON.stringify(nets)) 152}); 153``` 154 155## connection.getConnectionProperties 156 157getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback\<ConnectionProperties>): void 158 159Obtains connection properties of the network corresponding to given network handle. This API uses an asynchronous callback to return the result. 160 161**Required permission**: ohos.permission.GET_NETWORK_INFO 162 163**System capability**: SystemCapability.Communication.NetManager.Core 164 165**Parameters** 166 167| Name | Type | Mandatory| Description | 168| --------- | ------------------------------------------------------------ | ---- | ---------------- | 169| netHandle | [NetHandle](#nethandle) | Yes | Network handle.| 170| callback | AsyncCallback\<[ConnectionProperties](#connectionproperties)> | Yes | Callback used to return the result. | 171 172**Example** 173 174```javascript 175connection.getDefaultNet().then(function (netHandle) { 176 connection.getConnectionProperties(netHandle, function (error, info) { 177 console.log(JSON.stringify(error)) 178 console.log(JSON.stringify(info)) 179 }) 180}) 181``` 182 183## connection.getConnectionProperties 184 185getConnectionProperties(netHandle: NetHandle): Promise\<ConnectionProperties> 186 187Obtains connection properties of the network corresponding to **netHandle**. This API uses a promise to return the result. 188 189**Required permission**: ohos.permission.GET_NETWORK_INFO 190 191**System capability**: SystemCapability.Communication.NetManager.Core 192 193**Parameters** 194 195| Name | Type | Mandatory| Description | 196| --------- | ----------------------- | ---- | ---------------- | 197| netHandle | [NetHandle](#nethandle) | Yes | Network handle.| 198 199**Return Value** 200 201| Type | Description | 202| ------------------------------------------------------- | --------------------------------- | 203| Promise\<[ConnectionProperties](#connectionproperties)> | Promise used to return the result.| 204 205**Example** 206 207```javascript 208connection.getDefaultNet().then(function (netHandle) { 209 connection.getConnectionProperties(netHandle).then(function (info) { 210 console.log(JSON.stringify(info)) 211 }) 212}) 213``` 214 215## connection.getNetCapabilities 216 217getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback\<NetCapabilities>): void 218 219Obtains capability information of the network corresponding to **netHandle**. This API uses an asynchronous callback to return the result. 220 221**Required permission**: ohos.permission.GET_NETWORK_INFO 222 223**System capability**: SystemCapability.Communication.NetManager.Core 224 225**Parameters** 226 227| Name | Type | Mandatory| Description | 228| --------- | --------------------------------------------------- | ---- | ---------------- | 229| netHandle | [NetHandle](#nethandle) | Yes | Network handle.| 230| callback | AsyncCallback\<[NetCapabilities](#netcapabilities)> | Yes | Callback used to return the result. | 231 232**Example** 233 234```javascript 235connection.getDefaultNet().then(function (netHandle) { 236 connection.getNetCapabilities(netHandle, function (error, info) { 237 console.log(JSON.stringify(error)) 238 console.log(JSON.stringify(info)) 239 }) 240}) 241``` 242 243## connection.getNetCapabilities 244 245getNetCapabilities(netHandle: NetHandle): Promise\<NetCapabilities> 246 247Obtains capability information of the network corresponding to **netHandle**. This API uses a promise to return the result. 248 249**Required permission**: ohos.permission.GET_NETWORK_INFO 250 251**System capability**: SystemCapability.Communication.NetManager.Core 252 253**Parameters** 254 255| Name | Type | Mandatory| Description | 256| --------- | ----------------------- | ---- | ---------------- | 257| netHandle | [NetHandle](#nethandle) | Yes | Network handle.| 258 259**Return Value** 260 261| Type | Description | 262| --------------------------------------------- | --------------------------------- | 263| Promise\<[NetCapabilities](#netcapabilities)> | Promise used to return the result.| 264 265**Example** 266 267```javascript 268connection.getDefaultNet().then(function (netHandle) { 269 connection.getNetCapabilities(netHandle).then(function (info) { 270 console.log(JSON.stringify(info)) 271 }) 272}) 273``` 274 275## connection.reportNetConnected 276 277reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void 278 279Reports connection of the data network. This API uses an asynchronous callback to return the result. 280 281**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 282 283**System capability**: SystemCapability.Communication.NetManager.Core 284 285**Parameters** 286| Name| Type| Mandatory| Description| 287| -------- | -------- | -------- | -------- | 288| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).| 289| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 290 291**Example** 292 293``` 294connection.getDefaultNet().then(function (netHandle) { 295 connection.reportNetConnected(netHandle, function (error) { 296 console.log(JSON.stringify(error)) 297 }); 298}); 299``` 300 301 302## connection.reportNetConnected 303 304reportNetConnected(netHandle: NetHandle): Promise<void> 305 306Reports connection of the data network. This API uses a promise to return the result. 307 308**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 309 310**System capability**: SystemCapability.Communication.NetManager.Core 311 312**Parameters** 313| Name| Type| Mandatory| Description| 314| -------- | -------- | -------- | -------- | 315| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).| 316 317**Return Value** 318| Type| Description| 319| -------- | -------- | 320| Promise<void> | Promise used to return the result.| 321 322**Example** 323 324``` 325connection.getDefaultNet().then(function (netHandle) { 326 connection.reportNetConnected(netHandle).then(function () { 327 console.log(`report success`) 328 }); 329}); 330``` 331 332 333## connection.reportNetDisconnected 334 335reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void 336 337Reports disconnection of the data network. This API uses an asynchronous callback to return the result. 338 339**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 340 341**System capability**: SystemCapability.Communication.NetManager.Core 342 343**Parameters** 344| Name| Type| Mandatory| Description| 345| -------- | -------- | -------- | -------- | 346| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).| 347| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 348 349**Example** 350 351``` 352connection.getDefaultNet().then(function (netHandle) { 353 connection.reportNetDisconnected(netHandle, function (error) { 354 console.log(JSON.stringify(error)) 355 }); 356}); 357``` 358 359 360## connection.reportNetDisconnected 361 362reportNetDisconnected(netHandle: NetHandle): Promise<void> 363 364Reports disconnection of the data network. This API uses a promise to return the result. 365 366**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 367 368**System capability**: SystemCapability.Communication.NetManager.Core 369 370**Parameters** 371| Name| Type| Mandatory| Description| 372| -------- | -------- | -------- | -------- | 373| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).| 374 375**Return Value** 376| Type| Description| 377| -------- | -------- | 378| Promise<void> | Promise used to return the result.| 379 380**Example** 381 382``` 383connection.getDefaultNet().then(function (netHandle) { 384 connection.reportNetDisconnected(netHandle).then(function () { 385 console.log(`report success`) 386 }); 387}); 388``` 389 390## connection.getAddressesByName 391 392getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void 393 394Resolves the host name by using the default network to obtain all IP addresses. This API uses an asynchronous callback to return the result. 395 396**Required permission**: ohos.permission.GET_NETWORK_INFO 397 398**System capability**: SystemCapability.Communication.NetManager.Core 399 400**Parameters** 401 402| Name | Type | Mandatory| Description | 403| -------- | ------------------------------------------------- | ---- | ------------------ | 404| host | string | Yes | Host name to be resolved.| 405| callback | AsyncCallback\<Array\<[NetAddress](#netaddress)>> | Yes | Callback used to return the result. | 406 407**Example** 408 409``` 410let host = "xxxx"; 411connection.getAddressesByName(host, function (error, addresses) { 412 console.log(JSON.stringify(error)) 413 console.log(JSON.stringify(addresses)) 414}) 415``` 416 417## connection.getAddressesByName 418 419getAddressesByName(host: string): Promise\<Array\<NetAddress>> 420 421Resolves the host name by using the default network to obtain all IP addresses. This API uses a promise to return the result. 422 423**Required permission**: ohos.permission.GET_NETWORK_INFO 424 425**System capability**: SystemCapability.Communication.NetManager.Core 426 427**Parameters** 428 429| Name| Type | Mandatory| Description | 430| ------ | ------ | ---- | ------------------ | 431| host | string | Yes | Host name to be resolved.| 432 433**Return Value** 434 435| Type | Description | 436| ------------------------------------------- | ----------------------------- | 437| Promise\<Array\<[NetAddress](#netaddress)>> | Promise used to return the result.| 438 439**Example** 440 441``` 442let host = "xxxx"; 443connection.getAddressesByName(host).then(function (addresses) { 444 console.log(JSON.stringify(addresses)) 445}) 446``` 447 448## connection.createNetConnection 449 450createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection 451 452Obtains the handle of the network specified by **netSpecifier**. 453 454**System capability**: SystemCapability.Communication.NetManager.Core 455 456**Parameters** 457 458| Name | Type | Mandatory| Description | 459| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 460| netSpecifier | [NetSpecifier](#netspecifier) | No | Network specifier. If this parameter is not set, the default network is used. | 461| timeout | number | No | Timeout interval for obtaining the network specified by **netSpecifier**. This parameter is valid only when **netSpecifier** is set.| 462 463**Return Value** 464 465| Type | Description | 466| ------------------------------- | -------------------- | 467| [NetConnection](#netconnection) | Handle of the network specified by **netSpecifier**.| 468 469**Example** 470 471```javascript 472// Default network 473let netConnection = connection.createNetConnection() 474 475// Cellular network 476let netConnectionCellular = connection.createNetConnection({ 477 netCapabilities: { 478 bearerTypes: [NetBearType.BEARER_CELLULAR] 479 } 480}) 481``` 482 483## NetConnection 484 485Represents the network connection handle. 486 487### on('netAvailable') 488 489on(type: 'netAvailable', callback: Callback\<NetHandle>): void 490 491Registers a listener for **netAvailable** events. 492 493**System capability**: SystemCapability.Communication.NetManager.Core 494 495**Parameters** 496 497| Name | Type | Mandatory| Description | 498| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 499| type | string | Yes | Event type. The value is fixed to **netAvailable**.<br>**netAvailable**: event indicating that the data network is available.| 500| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. | 501 502**Example** 503 504```javascript 505netConnection.on('netAvailable', function (data) { 506 console.log(JSON.stringify(data)) 507}) 508``` 509 510### on('netCapabilitiesChange') 511 512on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void 513 514Registers a listener for **netCapabilitiesChange** events. 515 516**System capability**: SystemCapability.Communication.NetManager.Core 517 518**Parameters** 519 520| Name | Type | Mandatory| Description | 521| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 522| type | string | Yes | Event type. The value is fixed to **netCapabilitiesChange**.<br>**netCapabilitiesChange**: event indicating that he network capabilities have changed.| 523| callback | Callback<{ netHandle: [NetHandle](#nethandle), netCap: [NetCapabilities](#netcapabilities) }> | Yes | Callback used to return the result. | 524 525**Example** 526 527```javascript 528netConnection.on('netCapabilitiesChange', function (data) { 529 console.log(JSON.stringify(data)) 530}) 531``` 532 533### on('netConnectionPropertiesChange') 534 535on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void 536 537Registers a listener for **netConnectionPropertiesChange** events. 538 539**System capability**: SystemCapability.Communication.NetManager.Core 540 541**Parameters** 542 543| Name | Type | Mandatory| Description | 544| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 545| type | string | Yes | Event type. The value is fixed to **netConnectionPropertiesChange**.<br>**netConnectionPropertiesChange**: event indicating that network connection properties have changed.| 546| callback | Callback<{ netHandle: [NetHandle](#nethandle), connectionProperties: [ConnectionProperties](#connectionproperties) }> | Yes | Callback used to return the result. | 547 548**Example** 549 550```javascript 551netConnection.on('netConnectionPropertiesChange', function (data) { 552 console.log(JSON.stringify(data)) 553}) 554``` 555 556### on('netBlockStatusChange') 557 558on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void 559 560Registers a listener for **netBlockStatusChange** events. 561 562**System capability**: SystemCapability.Communication.NetManager.Core 563 564**Parameters** 565 566| Name | Type | Mandatory| Description | 567| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 568| type | string | Yes | Event type. The value is fixed to **netBlockStatusChange**.<br>**netBlockStatusChange**: event indicating a change in the network blocking status.| 569| callback | Callback<{ netHandle: [NetHandle](#nethandle), blocked: boolean }> | Yes | Callback used to return the result. | 570 571**Example** 572 573```javascript 574netConnection.on('netBlockStatusChange', function (data) { 575 console.log(JSON.stringify(data)) 576}) 577``` 578 579### on('netLost') 580 581on(type: 'netLost', callback: Callback\<NetHandle>): void 582 583Registers a listener for **netLost** events. 584 585**System capability**: SystemCapability.Communication.NetManager.Core 586 587**Parameters** 588 589| Name | Type | Mandatory| Description | 590| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 591| type | string | Yes | Event type. The value is fixed to **netLost**.<br>netLost: event indicating that the network is interrupted or normally disconnected.| 592| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. | 593 594**Example** 595 596```javascript 597let netConnection1 = connection.createNetConnection() 598netConnection1.on('netLost', function (data) { 599 console.log(JSON.stringify(data)) 600}) 601``` 602 603### on('netUnavailable') 604 605on(type: 'netUnavailable', callback: Callback\<void>): void 606 607Registers a listener for **netUnavailable** events. 608 609**System capability**: SystemCapability.Communication.NetManager.Core 610 611**Parameters** 612 613| Name | Type | Mandatory| Description | 614| -------- | --------------- | ---- | ------------------------------------------------------------ | 615| type | string | Yes | Event type. The value is fixed to **netUnavailable**.<br>**netUnavailable**: event indicating that the network is unavailable.| 616| callback | Callback\<void> | Yes | Callback used to return the result. | 617 618**Example** 619 620```javascript 621netConnection.on('netUnavailable', function (data) { 622 console.log(JSON.stringify(data)) 623}) 624``` 625 626### register 627 628register(callback: AsyncCallback\<void>): void 629 630Registers a listener for network status changes. 631 632**Required permission**: ohos.permission.GET_NETWORK_INFO 633 634**System capability**: SystemCapability.Communication.NetManager.Core 635 636**Parameters** 637 638| Name | Type | Mandatory| Description | 639| -------- | -------------------- | ---- | ---------- | 640| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 641 642**Example** 643 644```javascript 645netConnection.register(function (error) { 646 console.log(JSON.stringify(error)) 647}) 648``` 649 650### unregister 651 652unregister(callback: AsyncCallback\<void>): void 653 654Unregisters the listener for network status changes. 655 656**System capability**: SystemCapability.Communication.NetManager.Core 657 658**Parameters** 659 660| Name | Type | Mandatory| Description | 661| -------- | -------------------- | ---- | ---------- | 662| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 663 664**Example** 665 666```javascript 667netConnection.unregister(function (error) { 668 console.log(JSON.stringify(error)) 669}) 670``` 671 672## NetHandle 673 674Defines the handle of the data network. 675 676Before invoking NetHandle APIs, call **getNetHandle** to obtain a **NetHandle** object. 677 678**System capability**: SystemCapability.Communication.NetManager.Core 679 680### Parameters 681 682| Name| Type | Description | 683| ------ | ------ | ------------------------- | 684| netId | number | Network ID. The value must be greater than or equal to 100.| 685 686### getAddressesByName 687 688getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void 689 690Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses an asynchronous callback to return the result. 691 692**Required permission**: ohos.permission.GET_NETWORK_INFO 693 694**System capability**: SystemCapability.Communication.NetManager.Core 695 696**Parameters** 697 698| Name | Type | Mandatory| Description | 699| -------- | ------------------------------------------------- | ---- | ------------------ | 700| host | string | Yes | Host name to be resolved.| 701| callback | AsyncCallback\<Array\<[NetAddress](#netaddress)>> | Yes | Callback used to return the result. | 702 703**Example** 704 705```javascript 706connection.getDefaultNet().then(function (netHandle) { 707 let host = "xxxx"; 708 netHandle.getAddressesByName(host, function (error, addresses) { 709 console.log(JSON.stringify(error)) 710 console.log(JSON.stringify(addresses)) 711 }) 712}) 713``` 714 715### getAddressesByName 716 717getAddressesByName(host: string): Promise\<Array\<NetAddress>> 718 719Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses a promise to return the result. 720 721**Required permission**: ohos.permission.GET_NETWORK_INFO 722 723**System capability**: SystemCapability.Communication.NetManager.Core 724 725**Parameters** 726 727| Name| Type | Mandatory| Description | 728| ------ | ------ | ---- | ------------------ | 729| host | string | Yes | Host name to be resolved.| 730 731**Return Value** 732 733| Type | Description | 734| ------------------------------------------- | ----------------------------- | 735| Promise\<Array\<[NetAddress](#netaddress)>> | Promise used to return the result.| 736 737**Example** 738 739```javascript 740connection.getDefaultNet().then(function (netHandle) { 741 let host = "xxxx"; 742 netHandle.getAddressesByName(host).then(function (addresses) { 743 console.log(JSON.stringify(addresses)) 744 }) 745}) 746``` 747 748### getAddressByName 749 750getAddressByName(host: string, callback: AsyncCallback\<NetAddress>): void 751 752Resolves the host name by using the corresponding network to obtain the first IP address. This API uses an asynchronous callback to return the result. 753 754**Required permission**: ohos.permission.GET_NETWORK_INFO 755 756**System capability**: SystemCapability.Communication.NetManager.Core 757 758**Parameters** 759 760| Name | Type | Mandatory| Description | 761| -------- | ----------------------------------------- | ---- | ------------------ | 762| host | string | Yes | Host name to be resolved.| 763| callback | AsyncCallback\<[NetAddress](#netaddress)> | Yes | Callback used to return the result. | 764 765**Example** 766 767```javascript 768connection.getDefaultNet().then(function (netHandle) { 769 let host = "xxxx"; 770 netHandle.getAddressByName(host, function (error, address) { 771 console.log(JSON.stringify(error)) 772 console.log(JSON.stringify(address)) 773 }) 774}) 775``` 776 777### getAddressByName 778 779getAddressByName(host: string): Promise\<NetAddress> 780 781Resolves the host name by using the corresponding network to obtain the first IP address. This API uses a promise to return the result. 782 783**Required permission**: ohos.permission.GET_NETWORK_INFO 784 785**System capability**: SystemCapability.Communication.NetManager.Core 786 787**Parameters** 788 789| Name| Type | Mandatory| Description | 790| ------ | ------ | ---- | ------------------ | 791| host | string | Yes | Host name to be resolved.| 792 793**Return Value** 794 795| Type | Description | 796| ----------------------------------- | ------------------------------- | 797| Promise\<[NetAddress](#netaddress)> | Promise used to return the result.| 798 799**Example** 800 801```javascript 802connection.getDefaultNet().then(function (netHandle) { 803 let host = "xxxx"; 804 netHandle.getAddressByName(host).then(function (address) { 805 console.log(JSON.stringify(address)) 806 }) 807}) 808``` 809 810## NetSpecifier 811 812Provides an instance that bears data network capabilities. 813 814**System capability**: SystemCapability.Communication.NetManager.Core 815 816| Name | Type | Description | 817| ----------------------- | ----------------------------------- | ------------------------------------------------------------ | 818| netCapabilities | [NetCapabilities](#netcapabilities) | Network transmission capabilities and bearer types of the data network. | 819| bearerPrivateIdentifier | string | Network identifier. The identifier of a Wi-Fi network is **wifi**, and that of a cellular network is **slot0** (corresponding to SIM card 1).| 820 821## NetCapabilities 822 823Defines the network capability set. 824 825**System capability**: SystemCapability.Communication.NetManager.Core 826 827| Name | Type | Description | 828| --------------------- | ---------------------------------- | ------------------------ | 829| linkUpBandwidthKbps | number | Uplink (from the device to the network) bandwidth.| 830| linkDownBandwidthKbps | number | Downlink (from the network to the device) bandwidth.| 831| networkCap | Array<[NetCap](#netcap)> | Network capability. | 832| bearerTypes | Array<[NetBearType](#netbeartype)> | Network type. | 833 834## NetCap 835 836Defines the network capability. 837 838**System capability**: SystemCapability.Communication.NetManager.Core 839 840| Name | Value | Description | 841| ------------------------ | ---- | ---------------------- | 842| NET_CAPABILITY_MMS | 0 | The network can connect to the carrier's Multimedia Messaging Service Center (MMSC) to send and receive multimedia messages.| 843| NET_CAPABILITY_NOT_METERED | 11 | The network traffic is not metered.| 844| NET_CAPABILITY_INTERNET | 12 | The network can connect to the Internet.| 845| NET_CAPABILITY_NOT_VPN | 15 | The network does not use a Virtual Private Network (VPN).| 846| NET_CAPABILITY_VALIDATED | 16 | The network is available. | 847 848## NetBearType 849 850Defines the network type. 851 852**System capability**: SystemCapability.Communication.NetManager.Core 853 854| Name | Value | Description | 855| --------------- | ---- | ----------- | 856| BEARER_CELLULAR | 0 | Cellular network | 857| BEARER_WIFI | 1 | Wi-Fi network| 858| BEARER_ETHERNET | 3 | Ethernet network| 859 860## ConnectionProperties 861 862Defines the network connection properties. 863 864**System capability**: SystemCapability.Communication.NetManager.Core 865 866| Name | Type | Description | 867| ------------- | ---------------------------------- | ---------------- | 868| interfaceName | string | NIC card name. | 869| domains | string | Domain. The default value is **""**.| 870| linkAddresses | Array<[LinkAddress](#linkaddress)> | Link information. | 871| routes | Array<[RouteInfo](#routeinfo)> | Route information. | 872| dnses | Array<[NetAddress](#netaddress)> | Network address. For details, see [NetAddress](#netaddress).| 873| mtu | number | Maximum transmission unit (MTU). | 874 875## LinkAddress 876 877Network link information. 878 879**System capability**: SystemCapability.Communication.NetManager.Core 880 881| Name | Type | Description | 882| ------------ | ------------------------- | -------------------- | 883| address | [NetAddress](#netaddress) | Link address. | 884| prefixLength | number | Length of the link address prefix.| 885 886## RouteInfo 887 888Network route information. 889 890**System capability**: SystemCapability.Communication.NetManager.Core 891 892| Name | Type | Description | 893| -------------- | --------------------------- | ---------------- | 894| interface | string | NIC card name. | 895| destination | [LinkAddress](#linkaddress) | Destination IP address. | 896| gateway | [NetAddress](#netaddress) | Gateway address. | 897| hasGateway | boolean | Whether a gateway is present. | 898| isDefaultRoute | boolean | Whether the route is the default route.| 899 900## NetAddress 901 902Defines the network address. 903 904**System capability**: SystemCapability.Communication.NetManager.Core 905 906| Name | Type | Description | 907| ------- | ------ | ------------------------------ | 908| address | string | Network address. | 909| family | number | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.| 910| port | number | Port number. The value ranges from **0** to **65535**. |