IP address Dynamic or static - networking

I have a laptop and a mobile phone both connected to a common wifi. I need to send data from phone to laptop using MQTT protocol. I would like to know whether my laptop's IP will change or will it be the same . If IP will change, then each time I need to change IP address in the program.

If you use the same modem or router to access the internet, it will give you the same IP adres until you are away for an x amount of time (usually weeks or months if not configured).
Unless you're not using an open wifi network, you're good to go!

Related

How to connect to raspberry Pi over internet if we know only its MAC Address

I have Raspberry Pi and a mobile app developed in ionic.It has to communicate over SocketIO and normal HTTP request. I can communicate if i know IP address and port no. But what if I'm using it over internet and my raspberry pi's IP address is changing dynamically due to DHCP. How do i connect to my raspberry Pi device. Is their a way to connect if I know MAC address of Rasspberry PI.
Short Answer: no
Slightly Longer:
MAC is only useful at Layer 2. So the minute you have a router between you and the device, you will no longer be able to see the MAC. If you control the Layer 2 network you can statically assign a DHCP address, or you can look at the logs and see what IP it was assigned, but if the device is connecting to networks you don't control and its address is changing, you will need a way for the Raspberry Pi to register where it currently lives. There are a variety of ways to do this, such as dynamic dns registration, or you could have it phone home to some sort of locator service that your app could then query, etc... But without extra software you are probably out of luck.
You should use a dynamic IP service like www.noip.com. They provide a free linux and/or windows client.
That way, when your public IP changes, you will still be able to connect.

Same ip address for multiple devices?

I want to develop an Android app that connects with a Windows desktop application via TCP/IP.
However I have very little knowledge of networking and so please forgive me if this is a very basic doubt.
My Windows based laptop as well as Android phone are connected to the internet via the same WiFi router.
Now I checked the IP address for my laptop as well as phone using a website.
Both are same!
If both have the same IP address, then to achieve networking between these devices I will choose different set of port numbers.
Will this connection work?
Is the connection happening via the internet or just locally on my
router?
EDIT: After reading the answer from #Doon, I have broadened my question.
Let's say the local address of laptop is 192.168.1.10 and that of phone is 192.168.1.20.
If I code my application to use these IP addresses, it should work as it is a local network.
But what if I want my laptop to connect with another phone which is not connected to the WiFi router, rather by 3G network.
Then which IP address should be used for the laptop and the other phone?
Since I am not allowed to use any other server, I am going to use port forwarding i.e. the user will type in the IP address displayed on the other device. The connection could be initiated on either one of the devices.
If you could also show how to do this programmatically, it would be very helpful.
My Windows application is developed in C++ using Qt.
All of your devices are sharing 1 external or WAN IP address using NAPT (network address port translation). Internally on your LAN each device has its own address. So yes it will work but you are going to need to use internal addrss and the devices actual IP address not its perceived address via an external service.
As for the connection locally or via router that all depends on where you are connecting to. If both end points are on your lan or on the same Subnet then the router will not be involved. So in the average home network between your phone and desktop both connected to the same network say via wifi then they are most likely layer 2 adjacent (see the OSI 7 layer model for more info on layer 2 vs layer 3). But once they are not on the same network then routing will be involved and your router will be used. If the phone is connected to 3G or the cell data network and you want it to talk to your desktop on your home network you are going to need to deal with port forwarding on your router and other such fun things.
In regards to updates. Once you leave the local network it gets more complicated especially with IPv4 as address are running out so there is more and more use of nat or IPv6 with 6 to 4 gateways. Do you want the laptop to initiate connect to the phone or phone to the laptop? But normally you will need to iterate your address on your interfaces. Then connect with an external service to get your external IP address and compare and see if they are the same. if both endpoints are dynamically assigned you will need some sort of location mechanism could be dynamic DNS could be locator service etc.

Getting the host ID and network ID from an IP address

I'm learning about IP addressing, and I'm still a bit confused. I know that an IP address consists of a network and host ID. To test this in the real world, I googled "what is my IP address" on my tablet and smartphone, both connected to my home wireless network and I got the same IP address. Shouldn't they be different since they are two different hosts? I suspect this has to do with public and private IP addresses, but then, my bigger question is how does data really get to my individual device?
To the outside "internet", your IP address is just the IP of your router, provided by your ISP. Within your home network, you have a set of private addresses assigned by your router. The way that programs know to communicate with the correct device is usually through a custom reply-to port that the router re-assigns to packets from each device. This is called NAT.
For example, if you are browsing on port 80 from your tablet and your laptop at the same time, your reply-to port may be set to 3245 for the tablet and 3246 for the laptop. When the router receives a packet going from port 80 to port 3245, it changes 3245 to 80 and sends it to your tablet. If the port is 3246, it sends it to your laptop instead. The key point here is that the website you are communicating only knows the IP of your home router. As far as those sites are concerned, there are no other devices.
To test this in the real world, I googled "what is my IP address" on my tablet and smartphone, both connected to my home wireless network and I got the same IP address. Shouldn't they be different since they are two different hosts?
No, because of NAT.
I suspect this has to do with public and private IP addresses, but then, my bigger question is how does data really get to my individual device?
Thanks to NAT.

Wake On LAN Configuration

I am trying to configure my laptop to be able to Wake On LAN via Magic Packets. I have a magic packet sniffer and it alerts me when a magic packet has been recieved(runs on target machine). The trouble is when I try to use the external ip address instead of the internal address. I have port forwarded port 9 to my internal ip(10.0.0.x, NOTE: x is only one digit). If I use the internal ip address, it tells me that a magic packet has been received. If I try the external ip address and sending from the target machine(to itself) it receives the magic packet. If I send it through a different machine or a website, it does not work. I am connected via ethernet cable(CAT 5). I also have the "Wake on LAN" setting in my BIOS set to "ENABLED". Also, my computer is set to "Allow this device to wake the computer". Am I doing something wrong?
P.S.
The solution to the previous problem was to start the Simple TCP/IP Service in Windows.
To use Wake on LAN across the internet (=> wake on WAN), you must do one of these things :
Edit your router's ARP table so it can forward the magic pack to the target computer with its MAC address
Port forward to LAN broadcast address so the target computer will always receive any magic packet sent to your router until it is plugged to the router
Buy a router with a built-in wake on lan feature (like DD-WRT open source firmware)
Use a magic packet repeater to forward magic packets to the broadcast address. This one should be always powered on
I'm using the fourth option to wake my home computer from my work. I bought an Arduino Uno + Ethernet shield and wrote a little program to do the job (forward magic packet). I set a port forward rule into my router (Netgear DG834G) to forward UDP 9 to the Arduino IP address.
I wrote a tutorial about this on my personal website, it's in French but code is universal ^^ : http://www.finalclap.com/tuto/arduino-wake-on-lan-repeater-80/
I did some more research and it turns out that unless the router itself has a built in management and can be accessed publicly, WoL will not work behind a router. WoL will work however if you have a device already inside the network send the magic packet to the target machine. THat completely destroys the point of WoL!

IOS4 - Send data using UDP socket on Wifi

I am trying to send data using the AsyncUDPSocket class. And I can send data using the iPhone simulator over the wire to another machine that is running a simple C-coded listening server. I can also receive data over the wire using a client connected to the simulator(server). However, when I tried the same over Wifi, using the simulator, I could only send data but not receive any data.
I read on another post, that unicast data makes this possible. How can I acheive this using AsyncUDPSocket?
Thanks,
Angelo.
Ok, I figured this out. A newbie kind of thing, really.
When I set my Mac network preferences to Ethernet, I get an IP for me to communicate. However, when I turn Airport(Wi-Fi for more newbies) ON, and ethernet cable disconnected, I checked my network preferences, and sure enough my IP address was a different one.
Spoke to a friend (an ace in networking) and the thing clicked immediately: On WiFi networks a DHCP server allocates an IP address. This IP address has to be reserved, at the very least, at the DHCP server. Since my IP was not reserved, I had to change the IP address, in my udp_client.c file, recompile and run the client to connect.
BTW, I can now communicate between my iPhone and my PC using my local WiFi (office) network.
For any who might face the same problem, do not be assured that the IP address of your mchine is the same, when you switch from LAN to Wifi, and use the device mostly for WiFi reated testing. :)

Resources