Open a port
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
9 posts
Page 1 of 1
Hey Coders,
How do I open a port (the specific prot is: 25565) on my computer? I need this to test some application I made which i might releas in the future. +rep for the one who helps me out,
thanks.
Regards,
clanc789
How do I open a port (the specific prot is: 25565) on my computer? I need this to test some application I made which i might releas in the future. +rep for the one who helps me out,
thanks.
Regards,
clanc789
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
25565 is the default port for Minecraft servers, do you plan on making one? 
Well, to open a port, go to your router's IP address using any web browser, the default IP for Linksys routers is 192.168.1.1. Then login with the router username and password. You might see a 'Games' section and a link to some 'Port mappings' or 'Open ports', thats often the place where you can change port mappings. You would also need to setup a static IP on your computer. So when you have done the above steps, you must select what port to open, and enter the static IP address to your computer that the traffic will be redirected to. If none of this made any sense, check this out http://portforward.com/.

Well, to open a port, go to your router's IP address using any web browser, the default IP for Linksys routers is 192.168.1.1. Then login with the router username and password. You might see a 'Games' section and a link to some 'Port mappings' or 'Open ports', thats often the place where you can change port mappings. You would also need to setup a static IP on your computer. So when you have done the above steps, you must select what port to open, and enter the static IP address to your computer that the traffic will be redirected to. If none of this made any sense, check this out http://portforward.com/.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

I ment, is there no VB.net code to open a port? Oh and yes it is about minecraft
:D

Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
That code may vary from model to model, but if you router supports UPnP (Universal Plug'n'Play) there is some common code to do it.
First open the Add Reference dialog. In the COM tab, find NATUPNP.DLL (NATUPnP Type Library 1.0) and add it to your project.
Then in your code, import the NATUPNPLib namespace and add a variable in you class.
To remove/close a port mapping, use this code
First open the Add Reference dialog. In the COM tab, find NATUPNP.DLL (NATUPnP Type Library 1.0) and add it to your project.
Then in your code, import the NATUPNPLib namespace and add a variable in you class.
Code: Select all
To open a port, you can use the following piece of code Private NATClass As UPnPNAT = New UPnPNAT()
Code: Select all
Replace '192.168.1.4' with the static IP address that you must have set up before using the code. Just search for 'Static IP Address' on Google.NATClass.StaticPortMappingCollection.Add(25565, "TCP", 25565, "192.168.1.4", true, "Minecraft server")
To remove/close a port mapping, use this code
Code: Select all
The full code is now
NATClass.StaticPortMappingCollection.Remove(25565, "TCP")
Code: Select all
Imports NATUPNPLib
Public Class Form1
Private NATClass As UPnPNat = New UPnPNAT()
Private Sub OpenPort()
NATClass.StaticPortMappingCollection.Add(25565, "TCP", 25565, "192.168.1.4", true, "Minecraft server") 'The parameters are: External port, Protocol, Internal port, Static IP of your PC, Enabled, Description'
End Sub
Private Sub ClosePort()
NATClass.StaticPortMappingCollection.Remove(25565, "TCP") 'The parameters are: External port, Protocol'
End Sub
Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form1.Load
MessageBox.Show("Opening port 25565")
OpenPort()
MessageBox.Show("Closing port 25565")
ClosePort()
End Sub
End Class
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

Ill look at that tomorrow
Thx for the help already!

Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
Opening a port is not the same as forwarding it from your router.
If you are using a firewall then you will need to open the port by adding it to a list of exceptions; and this code will be different to above.
If you are using a firewall then you will need to open the port by adding it to a list of exceptions; and this code will be different to above.
And how do I add it to the firewall exceptions. What rights are needed for that?
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
You can use this to open a port:
Code: Select all
Imports NetFwTypeLib 'COM Component
Code: Select all
You will need admin rights in order for this to work. Private Sub btnOpen_Click(sender As System.Object, e As System.EventArgs) Handles btnOpen.Click
Dim mgrType As Type = Type.GetTypeFromProgID("HNetCfg.FwMgr", True)
Dim manager As INetFwMgr = Activator.CreateInstance(mgrType)
Dim portType As Type = Type.GetTypeFromProgID("HNetCfg.FwOpenPort", True)
Dim port As INetFwOpenPort = Activator.CreateInstance(portType)
port.Name = "test"
port.Protocol = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP
port.Port = 1234
port.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_ALL
'port.IpVersion = NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4 'default
manager.LocalPolicy.CurrentProfile.GloballyOpenPorts.Add(port)
End Sub
Thanks mandai! Ill lock the topic now since its solved.
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023