If you have a firewall or a router, these are the ports "Heroes 3" needs:
2300 to 2400 TCP and UDP
6073 and 47624 TCP and UDP
Perhaps you can find some more useful information here about troubleshooting:
http://www.neoseeker.com/forums/1853/t479505-solutions-heroes-3-problems-windows-xp-combined-artifact-list/
Here's a quote from there:
Example: I have been trying to get Heroes 3 to work through my router for 6 weeks and finally figured it out two days ago. The problem I had was that everywhere I had read the advice was to make an entry in the "special applications" setup page of the router with a trigger port setting of 6073 or 47624, which you set to open the port range of 2300 to 2400 as you show above. This still did not solve the problem until I recently discovered that I needed to also add the trigger ports (6073 and 47624) to the "Virtual Server" setup section of my router. Now the game works fine through the router. Hope this helps someone else out.
Added 8 minutes ago
Regarding how it helped me solve the problems with the router.
First, I bought a new Asus WL-520GU router because previous attempts to flash it ended up bricking it.
Next, in the settings, go to WAN --> DMZ --> the only field where you can enter an IP address --> enter the IP address of your computer (you can find it when you launch Heroes in network mode and select TCP game; the address changes each time you restart your computer, so you need to update it).
This helped me to be a server and play online through Hamachi or GameRanger, but I still can't connect to other servers.
In continuation:
Connecting through GameRanger usually works; in rare cases, a connection cannot be established, and in this case, TeamViewer may help:
Playing through TeamViewer (may be a panacea for those who have connection problems through the router):
Download from http://www.teamviewer.com/ru/
Then, step-by-step installation:
1)

2)

3)

4)

5)

6)

7)

8)

9)

10)

11)

12)

Go to your email, click on the link in the email ==> Your account has been activated.
Launch TeamViewer:
- Click on "Remote Control"
- Your ID is visible on the left
- To connect to someone, you need to know their ID and password
- Enter the partner's ID
- Check the "VPN" box
- Click "Connect to partner"

A window appears, indicating that the connection has been established.
Your IP address, which the program assigned, and the IP address of the person you connected to are visible.
Then, launch Heroes in network mode, TCP IP.
Most likely, your IP address will be replaced with the IP address from TeamViewer.
To connect to you, the opponent needs to enter your IP address from TeamViewer.

15)

----------------------------------------------------------------------
To create a broadcast through TeamViewer:
- Conference tab
- Start a quick conference
- In the window that appears, you will see your broadcast number


Accordingly, to view someone else's broadcast, enter their ID and click "Join Conference".