Where is NodeMCU getting ip address from? - nodemcu

With a blank init.lua, whenever I reboot the NodeMCU:
=wifi.sta.getip()
192.168.1.108 255.255.255.0 192.168.1.1
Where is it getting this 192.168.1.108? At one time a couple of weeks ago, I was testing the wifi module. When it connected it was with this ip.
How can that info be hanging around? Or is this some sort of internal ip that NodeMCU uses?

The answer is in the docs for wifi.sta.config:
Station configuration will be retained until changed even if device is turned off.
So, if you used wifi.sta.config("ssid", "password") in the past the device will try to connect to the WiFi "ssid" and obtain an IP (from the DHCP server) whenever it boots.

Related

Local HTTP Server Only Access-able When Wifi is Turned Off

This was woorking for me a week ago and I have no idea what changed.
I have a local http server on one device that I'm accessing with my Mac (through javascript),they are directly connected through Ethernet/a switch. I have the ethernet network on my mac set to a manual ip/mask to reflect the address of my server.
I can interact with my server perfectly when wifi is turned off on my mac, however, when I turn it on everything breaks and my requests to the server time out with no response (wifi is still functional).
Things I've tried:
Changing the network priority in network system preferences on my mac to make sure the wired Ethernet connection takes priority over WiFi. This changed nothing
Added a static route sudo route add -host [ip of http server] -interface en10. After I changed this, the server was unreachable even when wifi was down so I may have done something wrong
rebooted :)
I'm super lost here - any advice or any debugging tips would be much appreciated!

Does netstat command show devices, printers on your wifi network?

What network utility on a MAC can help me see what devices, printers are available, listening etc on my wifi. Netstat does not seem to show me my printer or Android device. For example,
My macbook pro with ip address 10.1.140.255 but I can't see my Android phone with ip 10.1.140.77 or a printer on 10.1.140.95.
Considering that some of your devices may be passively just sitting there with no active connections to your computer, you can't find them by examining your computer; you'll have to go actively looking for them. That typically means a network scanner.
Here's a list: https://www.softwaretestinghelp.com/network-scanning-tools/
I like Nmap (https://nmap.org) with the Zenmap GUI (https://nmap.org/zenmap)
Just make sure you do this in your own network. Scanning somebody else's network will trigger alarms and is more than likely illegal.
Try arp -a instead. Netstat doesn't scan the network, it just provides information about your own device's connection to the network.
Edit: Try ifconfig | grep broadcast | arp -a
When you're on LAN, connecting to an IP involves resolving the IP into a mac address. ARP keeps a cache of all resolved IP addresses. Doing a broadcast ping indirectly triggers a resolution for all IPs on the network.
https://superuser.com/questions/124453/how-can-i-scan-the-local-network-for-connected-devices-mac-os

How to force MacOS to send network packets to local proxy even when Wi-Fi is not connected

MacOS version: Mojave
I have a program listening on a local port(2080). I would like to forward all network requests to this program.
In order to accomplish this, I have configured the Wi-Fi network service to use a socks5 proxy as well as dns server pointing to local host.
This works as long as the Wi-Fi network service is connected to any network, regardless wether that network is connected to the internet. (For instance, a chromecast).
Is there a way to force the packages to the program without having to connect to a network?
Previous attempts include creating a network service attached to the lookback device, lo0, with the proxy and dns settings as before (couldn't get any packets to be routed through the program, network panel says not connected) And installing tun/tap discussed in this question.(Virtual network interface in Mac OS X).
The device will show up in ifconfig, but not in network services after editing the SystemConfiguration/preferences.plist
Any guidance is welcomed.
Nevermind I figured it out. The Tun/Tap will work, just need to configure the virtual network service with correct DNS and proxy settings.

Raspberry Pi SSH connection over Ethernet fails

I'm trying to establish a connection over SSH from my Win 8.1 laptop to my raspberry pi 3 model B as the host. Connecting over wifi works flawlessly each time, however I need to demo projects in class and the campus wifi does not play well with SSH, our professor stated that we must use an Ethernet connection. I have tried both putty and Bitvise SSH clients with same results - either "connection refused" or "no connection could be made because the machine actively refused it".
I have tried:
Enabling internet sharing on the Ethernet connection and enabling the SSH services (port 22 both TCP and UDP)
Disabling wifi on Win
Forgetting wifi on raspberry
Manually activating SSH server on raspberry even though I'm pretty sure it was activated already.
Deleting SSH keys from the wifi sessions
Completely disabling the firewall
ipconfig /release ipconfig /renew
Restarting both machines after every of the above
Reimaging memory card with newest Raspbian
Any help would be greatly appreciated.
Edit: The link What can be the reasons of connection refused errors? did not help, the listed reasons are closed ports or firewall and as I already said I tried to open the required ports through the shared Ethernet connection and turned off Windows firewall completely with no other firewall programs running. From my understanding Raspbian doesn't come with any enabled firewalls and allows all traffic. Can someone correct me if I'm wrong?
I finally found a guide that works: http://www.circuitbasics.com/how-to-connect-to-a-raspberry-pi-directly-with-an-ethernet-cable/
The crucial step was to set the static IP address of the pi to my laptop's Ethernet adapter address but modify the last part. You're welcome, all you poor souls from the future.

Find IP address of directly connected device

Is there a way to find out the IP address of a device that is directly connected to a specific ethernet interface? I.e. given one host, one wired ethernet connection and one second host connected to this wired connection, which layer or protocol below IP could be used to find this out.
I would also be comfortable with a Windows-only solution using some Windows-API function or callback.
(I know that the real way to do this would probably via DHCP, but this is about discovering a legacy device.)
Mmh ... there are many ways.
I answer another network discovery question, and I write a little getting started.
Some tcpip stacks reply to icmp broadcasts.
So you can try a PING to your network broadcast address.
For example, you have ip 192.168.1.1 and subnet 255.255.255.0
ping 192.168.1.255
stop the ping after 5 seconds
watch the devices replies : arp -a
Note : on step 3. you get the lists of the MAC-to-IP cached entries, so there are also the hosts in your subnet you exchange data to in the last minutes, even if they don't reply to icmp_get.
Note (2) : now I am on linux. I am not sure, but it can be windows doesn't reply to icm_get via broadcast.
Is it the only one device attached to your pc ?
Is it a router or another simple pc ?
To use DHCP, you'd have to run a DHCP server on the primary and a client on the secondary; the primary could then query the server to find out what address it handed out. Probably overkill.
I can't help you with Windows directly. On Unix, the "arp" command will tell you what IP addresses are known to be attached to the local ethernet segment. Windows will have this same information (since it's a core part of the IP/Ethernet interface) but I don't know how you get at it.
Of course, the networking stack will only know about the other host if it has previously seen traffic from it. You may have to first send a broadcast packet on the interface to elicit some sort of response and thus populate the local ARP table.
Windows 7 has the arp command within it.
arp -a should show you the static and dynamic type interfaces connected to your system.
Your Best Approach is to install Wireshark, reboot the device wait for the TCP/UDP stream , broadcasts will announce the IP address for both Ethernet ports
This is especially useful when the device connected does not have DHCP Client enabled, then you can go from there.
You can also get information from directly connected networking devices, such as network switches with LDWin, a portable and free Windows program published on github:
http://www.sysadmit.com/2016/11/windows-como-saber-la-ip-del-switch-al-que-estoy-conectado.html
LDWin supports the following methods of link discovery: CDP (Cisco Discovery Protocol) and LLDP (Link Layer Discovery Protocol).
You can obtain the model, management IP, VLAN identifier, Port identifier, firmware version, etc.

Resources