Getting the local IP address
#1
Posted 28 May 2011 - 08:31 PM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#2
Posted 28 May 2011 - 08:42 PM
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress
- ramtinraji likes this
#3
Posted 28 May 2011 - 08:45 PM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#4
Posted 29 May 2011 - 09:50 AM
I tried this simple sample-code:
// Fetches the first network interface Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; // DHCP NI.EnableDhcp(); NI.ReleaseDhcpLease(); NI.RenewDhcpLease(); Debug.Print(NI.IPAddress.ToString()); // Static NI.EnableStaticIP("192.168.2.75", "255.255.255.0", "192.168.2.1"); Debug.Print(NI.IPAddress.ToString());
Output:
0.0.0.0
192.168.2.75
Using firmware: Netduino Plus (v4.1.1.0 b1 with extra RAM) by Secret La
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#5
Posted 01 June 2011 - 06:27 AM
Same issue with a Sitecom Wireless Gigabit Router 300N WL-368
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#6
Posted 02 June 2011 - 12:37 PM
#7
Posted 23 July 2011 - 02:26 AM
... but it displays 0.0.0.0 on my Netduino.
Try adding this code block afer you renew the dhcp lease, but before trying to use the IP address with Debug.Print. I found it in one of the Microsoft samples included with the .NET MicroFramework, including the relevent comment... the NetduinoPlus being an LWIP device:
NetworkInterface ni; // Wait for DHCP (on LWIP devices) while (true) { ni = NetworkInterface.GetAllNetworkInterfaces()[0]; if (ni.IPAddress != "0.0.0.0") break; Debug.Print("Waiting for an IP Address..."); Thread.Sleep(1000); }
-Valkyrie-MT
#8
Posted 15 November 2011 - 08:26 PM
#9
Posted 15 November 2011 - 08:28 PM
#10
Posted 15 November 2011 - 08:35 PM
Use [code=auto:0] tags around themok how come my code snipet looks like crap (unformatted and not in color like other posts?
I copied direct from visual studio and pasted into reply.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#11
Posted 15 November 2011 - 08:35 PM
Just replace { and } with [ and ]...
It will look like:
MyCode.IAmJustATest()
NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and down - and upload files
If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#12
Posted 15 November 2011 - 08:43 PM
#13
Posted 17 November 2011 - 03:55 AM
The above post had a flaw. Not much good doing a DHCP when afterward it gets hard wired >>> 192.168.2.75
// Wait for DHCP (on LWIP devices) while (true) { ni = NetworkInterface.GetAllNetworkInterfaces()[0]; if (ni.IPAddress != "0.0.0.0") break; Debug.Print("Waiting for an IP Address..."); Thread.Sleep(1000); } Debug.Print(NI.IPAddress.ToString()); // Static NI.EnableStaticIP("192.168.2.75", "255.255.255.0", "192.168.2.1"); Debug.Print(NI.IPAddress.ToString());
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users