Backport the new methods and bug fixes in NetUtil

Related:

- 37a6f5ed5dd56284ec37e14e0554e912f84426a1

Motivation:

Minimize the backport cost by synchronizing NetUtil between 3.9 and 4.x

Modifications:

- Backport the bug fixes in NetUtil
- Backport the new IP address methods in NetUtil

Result:

- New useful methods in NetUtil
- Easier to backport the future bug fixes