Can't access device through network - networking

I'm trying to interface a device with python.
The device is connected to another machine in the same network (the university network) and I know it's Port number.
I can access the device from the PC where it is plugged with the following code:
dev = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dev.connect(('137.195.53.140',51019))
where '137.195.53.140' is the PC ip, and 51019 is the port number.
However, if I try the same from another machine, ipython gets stack at the command "dev.connect(('137.195.53.140',51019))", and when I abort the evaluation and then look at "dev" I get this:
<socket.socket fd=15, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('137.195.204.85', 50393)>
where '137.195.204.85' is the IP of the machine I'm using, and the port number I've no idea.
Since ssh works with no problem within this network, I thought that my approach for accessing the device would have worked as well.
Does anyone have any clue for this? I'm sorry if I haven't been clear, but I know absolutely nothing of networking (and not very much of Python either tbh).

There's couple of things to consider:
Your university network ports
Your device's opened ports
Your network might have the 51019 port blocked. Also, ssh uses port 22 to make it's connection. Every port is a world, so there's the chance that just because 22 is open, it doesn't mean that another is. School networks usually have a pretty rigid policy on port closing for security and blocking unwanted sites too.
You can test your device access by pinging it as
$ ping 137.195.204.85
If that works, then you can go trying different ports

Related

Port number concepts?

I am trying to understand the concept of port number. As much as I know it identifies a specific process or a network service.
Can anyone give me a real life example. So, it could be easier to understand.
Some doubts that I currently have-
I heard, there are 65536 ports. Does, that mean, a system can identify 65536 processes simultaneously?
I have seen that some ports are reserve for some specific service. So, does it mean, it can't be used for any other service?
What is the command to know which port numbers are free or to use?
What is the command to know which port numbers are not free and what are they used for?
If I try to access a system through remote desktop from my computer, it asks for a port number. What should I mention?
If possible please share a link. I am currently getting confused with too much technical theory. Thank you!!!
I heard, there are 65536 ports.
You heard wrong. There are 65535: 1 .. 65535. Zero is not a valid port number.
Does, that mean, a system can identify 65536 processes simultaneously?
It means a system can identify 65535 ports simultaneously.
I have seen that some ports are reserve for some specific service. So, does it mean, it can't be used for any other service?
That is the meaning of the word 'reserve'.
What is the command to know which port numbers are free or to use?
It isn't a command. It is either a search at the IETF website for reserved ports or the use of the number zero, which means the next available port.
What is the command to know which port numbers are not free and what are they used for?
It isn't necessarily a command. It is a search at the IETF website for reserved ports, or the netstat command for ports actively in use on the localhost.
If I try to access a system through remote desktop from my computer, it asks for a port number. What should I mention?
The port number that you're trying to connect to in the remote system.
Here is more clarification:
I heard, there are 65536 ports.
A port is 16 bit i.e. 2^16 =65536 so right
"Port Zero does not officially exist. It is defined as an invalid port number. But valid Internet packets can be formed and sent over the wire to and from port 0 just as with any other ports." https://www.grc.com/port_0.htm
Does, that mean, a system can identify 65536 processes simultaneously?
You do not care about a system, you care about an IP. For every Ip you can use 65536 processes simultaneously.
I have seen that some ports are reserve for some specific service. So, does it mean, it can't be used for any other service?
Of course, otherwise there will be a port conflict.
What is the command to know which port numbers are free or to use?
Refer my post here https://stackoverflow.com/a/54760498/2197108
Netstat: in Linux and Windows displays connections and ports
What is the command to know which port numbers are not free and what are they used for?
It should be clear now
If I try to access a system through remote desktop from my computer, it asks for a port number. What should I mention?
Remote desktop asks for IP address of the remote machine. However, it may ask for user credentials of the remote machine.
In case it asks for IP and Port it means IP and Port of the remote desktop software (server) in the remote machine.

Local Network not allowing access to multiple computers

Not sure if I should ask this question here, but this is a technology community so why not.
I'm running a local network which is setup like this:
Modem -> Access Point -> Switch -> Server/5 other computers
and my problem is the 5 other computers only two computers can have access to the internet (which are connected though Ethernet).
Also, any device that's connected to my wireless network can't access the internet either.
I know it's not a problem from my ISP since two computers are connected to the internet. And I know it's not a wireless problem since my local server can be reached though the access point.
I'm not sure what is the problem since I replaced all the cables, devices, and done tons of resets.
Appreciate your help, or direction to where I can get help.
Thanks all, but my problem was that I used static IP and didn't assign more than three, two computers and a printer. completely a beginner's mistake.
I don't know if you are familiar with computer networks but I think it's a network problem. Maybe your router (modem) can provide only two IPs and that's why only two computers can connect the internet. To verify this you can check what is your IP, and what is your Subnet Mask. Type ipconfig in your cmd and give me your IP and the subnet mask to check if this is the problem or not.

Is there a way to detect the number of connections active on a Wifi network?

If I want to detect the number of connections active on my home Wifi network, how should I go ahead doing it? This can be useful for building applications which would serve as monitoring unidentified/unrecognized people being fraudulently misusing a person's Wifi network.
How to know whether your neighbors or others are using your wireless network is rather complicated.
If your neighbors are experienced Wi-Fi hackers, you might not be able to tell at all.
If they're just stealing your Internet connection, you may be able to tell from the logs on your router.
To find out who's on your wireless network, you'll need to start by taking inventory of all the devices that are meant to be connected. Find out their MAC IDs and their IP addresses (if they're static).
To find out the MAC ID/IP address on a PC, click the Start menu and choose Run. Type cmd and click OK. In the screen that opens, type ipconfig /all and hit Enter. The MAC address will be shown as the physical address. Once you know the MAC addresses of each of the PCs on your network, you will recognize any addresses that don’t belong under the screen that shows the MAC addresses of current connections.
Check IP addresses
Likewise you may be able to see how many IP addresses have been dished out by the DHCP server. If you check the IP addresses of each of your PCs, you can see if other IP addresses have been served.
To find out your IP address from the Start menu, click Run. Then type in cmd and click OK. In the screen that comes up, type ipconfig which will display the IP address for that computer. (Bear in mind, however, that if the PC is set to auto detect settings, then the PC's IP address will change the next time the computer is rebooted or switched on. Sometimes previously served numbers have not yet expired, so you may think someone is connected when they are not.)
Dealing with intruders
If you do find someone using your connection, they may well not be doing so maliciously or even knowingly. Sometimes people can’t tell which is their own connection and they may honestly believe that they are using their Wi-Fi router rather than yours. The best way to deal with this is to set up your own security and maybe you can help them find their own router!
The optimal solution is to set up a strong password using WPA or WPA 2 of almost 20 to 30 digits and numbers. Once your network is functioning, you can switch off the SSID broadcast (which prevents it from advertising the name of your network) so it would effectively disappear as far as your neighbors are concerned, and the first you might hear of it is when someone complains that their Web connection has disappeared.
You could look for logs such as current LAN clients, connection or status log, or connected MAC addresses.
Be Happy :-)
Do you have access to the Access Point management ?
Look for MAC addresses and their filtering. Modern APs allow you to filter devices and or limit the timeframe during which devices can authenticate themselves, using a hardware button.
A link on how to secure your AP here, and a good start to know what to play with !
You can Either USE this Command... On your Router or Modem... Some Modem's have console for Ping and Commands like that....
ipconfig -all

How do I get a MAC address for a remote system when I only know it's IP address?

I'm working on a Wake on LAN service that will run from a web site and should interact with many different platforms - therefore, no Windows-only solutions. When a user registers their system with the web site, I need to get the MAC address to use in constructing the "magic" packet. I have a Java Applet that is able to do this for me and am aware of an ActiveX control that will work, but I'm wondering if there is a way to do this server-side by querying routers/switches. Since the system may be on any of a number of different physical subnets, using ARP won't work -- unless there's a way to configure the router(s) to perform the ARP on my behalf.
Anyone know of any network APIs, proprietary or otherwise, that can be used to look up MAC addresses given an IP address? I think we're using Cisco routers, but it's a complicated network and there may be multiple vendors involved at various levels. I'd like to get some background information on possible solutions before I go to make a sacrifice to the network gods. No point in abasing myself if it's not technically possible. :-)
EDIT: We do have the network infrastructure set up to allow directed broadcast, though figuring out the exact broadcast address since netmasks are not always /24 is another conundrum that I need to solve.
If you are on a local network that uses DHCP you might be able to look in the servers database to get the MAC of the last user with that address. In the future you could watch the network for ARP requests and cache the responses in some sort of table. You might also look at using RMON or SNMP to try and query the Address Tables on the switches and routers.
It should be noted that to use WoL across routers you either need to enable Directed Broadcasts or you need to have a relay server in the local segment.
Been a while since I played routers and swtiches but this might be a starting point for what to query using SNMP http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a00801c9199.shtml
Use the following:
getmac /s destIp
To get the remote session Mac address.
I don't know if these might be helpful but take a look:
http://www.webdeveloper.com/forum/showthread.php?t=134120
http://www.qualitycodes.com/tutorial.php?articleid=19
You've said everything I can think of...
The source MAC address changes as a packet hops from device to device so unless the client is on the same subnet, the server won't be able to get the MAC address. (You would do it via ARP)
A signed java applet or activex control would be the easiest solution. It would be able to (almost passively) get all the networking info you need (IE doesn't even prompt to run a signed applet)
If you are fully aware of the network that is using the service then you could probably query a gateway's client-list via SNMP or CDP. You would be able to map out IP-Addresses to MAC addresses... but this is really vendor dependent (but common) and wouldn't be much better (imo) than having an applet.
Currently the application is using a Java 6 applet that allows me to extract both the hostname and the MAC address from the remote system. I don't like having this dependency on Java 6, but Snow Leopard and Windows both support it, so I can probably live with it.
On a related-front our networking folks approached me for some help with converting some existing code to ASP.NET. During the conversation I asked if they had live MAC address information (since they do port shutoffs based on suspicious network activity -- viruses/worms). Turns out they do and we may be able to leverage this project to get access to the information from the network database.
I don't think there is any way to accomplish this. When the IP packet goes via the first router the host's MAC information is lost (as you know MAC is only used in ethernet layer). If the router most close to your PC was capable of telling the remote MAC code to you, again it would only see the MAC of the next router between your PC and the "other end".
Start sacrificing.
There's no general way to do this in terms of the network unless you have no routers involved. With a router involved, you will never see the MAC address of the originating system.
This assumes that the originating system only ever has a single network interface, so has only a single MAC address.
In fact, are you even sure that your "magic packet" (whatever that is) will reach the system you want it to reach, through the routers? That sounds like a function the routers or other network infrastructure should be performing.
Mac address is only used on network segments, and is lost at each hop. Only IP is preserved for end-to-end - and even then the from ip address is rewritten when Natted. I guess my answer is, not possible unless everything is on the same network segment, or your routers are set up for proxy arp (which is not really realistic).
You can only get MAC entries in the ARP table for machines on the same network. If you connect to a machine via a router then you will only see the routers MAC address in the ARP table. So there is no way of knowing the foreign host’s MAC address unless it's a host on the same network (no routers involved).
And by the way there are many similar question already on SO.
if it's a windows system you can use NBTSTAT -A
this will return the netbios info and the IP is there
any Management system like SMS or Altiris will have this info
The DHCP server is a good idea
If it's local you can ping it and then quickly run ARP -a
look for the IP and the MAC will be there.
you might need to write a small batch file.
if you have access to the PC you can use WMI to access the info for the Nic with DHCP.
As said above we can get mac address from a known IP address if that host is in the same subnet. First ping that ip; then look at arp -a | grep and parse the string on nix* to get mac address.
We can issue system command from all programming languages standard API's and can parse the output to get mac address.Java api can ping an IP but I am not sure if we parse the ping output(some library can do it).
It would be better to avoid issuing system command and find an alternative solution as it is not really Platform Independent way of doing it.
Courtesy: Professor Saleem Bhatti

Raspberry Pi gets a 192.168.x.x address, but rest of my home network is 10.21.179.x

There is a lot of history here, so please bear with me.
Our home network used to be fine when we were with Comcast, but we wanted better speed and reliability, so we switched to FIOS. At that point, the Wifi connections from my Raspberry Pis stopped working. I got frustrated after a couple of weeks of trying to discover the cause of the problem and eventually put it aside.
The other day, I started to configure a new Raspberry Pi 4 that I plan to use on my new Sphero RVR. I set it up following the usual directions and the Pi connects to the Internet without problem over WiFi, but I can't ping it from my Windows 10 desktop.
So I started digging. I downloaded the Fing app onto my Pixel 3 Android phone and looked at the network. I immediately noticed that all the devices now have a 10.29.179.xxx addresses. That easily explains why I can't ping from my PC to the Raspberry Pi. They aren't in the same address space.
I did discover that I can ping the Raspberry Pi if I use the IPV6 address. I can even get PuTTY to connect using the IPv6 address, although I was unable to successfully login. I don't know what is causing the login problem, but it's probably something mundane.
I suspect that I can make my Rpi conform to the rest of the network using a static IP address, but that might cause problems if I take the robot somewhere else to demonstrate what it can do. What I would like to understand is why most of my network, using DHCP, is on the 10.x.x.x network and the Raspberry Pis seem to wind up with 192.168.1.xxx addresses.
One further wrinkle. We have two routers, the FIOS router, and a LinkSys WRT1900AC, which is the router on which WiFi is enabled.
I suspect this problem is caused by having the two routers or by something inherent in the way the Raspberry Pi interacts with DHCP.
I would like for my Raspberry Pi to configure with an IPv4 address I can use, no matter what network I am connecting it to, and I'd like to understand why this problem is happening in the first place.
Let me know what additional information you'd like to see.
* Additional Notes *
As to the comment that I have not done research. I spent a week reading through stackoverflow problems and reading up on documentation of DHCP without finding the answers to my question. I do not ask questions idley. I ask questions when I cannot find answers and need the help of people more expert than myself in the areas in which I am having trouble.
I have solved the login problem. It was a stupid password mistake.
So now I can login, over wifi, using the IPv6 address, but not with the IPv4 address.
On the FIOS router, both the 2.4 and 5GHz wifi channels are turned off.
As suggested by Ljm Dullaart, the problem was that there were two DHCP servers on the network. After I turned off the FIOS DHCP, my problems went away.

Resources