It is currently Mon Dec 11, 2017 5:08 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: LAN Broadcasting and IP
PostPosted: Tue Nov 15, 2016 11:28 pm 
Offline
User
User

Joined: Tue Jul 16, 2013 12:28 pm
Posts: 33
Hello guys!

I've done LAN Broadcasting, so my client program can find my server program in LAN.
The idea is - client is broadcasting, server answer and says his own ip address (192.168.79.2)

Server is getting his own local ip by connecting to himself thru UDP and receiving IP Address from it.

Code:
  FakeConnection = OpenNetworkConnection(Hostname(), UDPPort, #PB_Network_UDP)
  If FakeConnection
    LocalIP = GetClientIP(FakeConnection)
    CloseNetworkConnection(FakeConnection)
  EndIf
 
  ;IPString(LocalIP)


Client using this IP to connect to server.
It works alright on my own pc, if I run server and client, but when I run client on another PC, I get answer on broadcasting from server - server ip (192.168.79.2), but I cannot connect to it. Simply cant create a connection.

Checking IPs in cmd via ipconfig command I realized, that these two ips 192.168.72.2 (server PC) and 192.168.56.1 (client PC) are VirtualBox-HostOnly Network Adapter IPs.
Tho true Ethernet IPv4 addresses are 192.168.1.101 and 192.168.1.107 and using them I can connect successfully.

So, how can I get server real local ip (by real I mean not VirtualBox ones, but nice 192.168.1.101 ones), so it will tell client its ip and client will connect using it and not VirtualBox IPs.

P.s. Im not using VirtualBox for testing. There are only network adapters, that probably screw things up


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Wed Nov 16, 2016 3:26 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
i think you might need an EventClient() call in there. The logic to your code doesnt seem right to me either because you're asking for the IP address from the 'connection', but as you're using UDP there's no real connection, so i think you can only determine the IP address after an event like receiving data or disconnection

or if you meant "how do i get my internet IP address instead of internal LAN/VM one" you might need to call out to one of those free public "whatsmyip" websites for that

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Wed Nov 16, 2016 1:27 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 12, 2013 1:55 pm
Posts: 1052
Location: just outside of Ferguson
Something like this is what I do to find the first two LAN physical NIC IP addresses on a machine.
The first one is usually the loopback address.

Code:
If InitNetwork() = 0 : MessageRequester("PROGRAM","Could not initialize network interface.") : End : EndIf
ExamineIPAddresses() : IND= NextIPAddress()
If IND : INTADDR$= IPString(IND) : IND= NextIPAddress() : If IND : INTADDR2$= IPString(IND) : IND= NextIPAddress() : If IND : INTADDR3$= IPString(IND) : EndIf : EndIf : EndIf

_________________
Keep it BASIC.


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Wed Nov 16, 2016 7:14 pm 
Offline
User
User

Joined: Tue Jul 16, 2013 12:28 pm
Posts: 33
Keya, UDP is connectionless protocol, right, but you still can get the local IP of the host. I run that "fake connection" code on server. Server creates connection to itself using Hostname() instead of IP, and then, using GetClientIP() server gets the local IP address of himself, instead of Hostname.

Con = OpenNetworkConnection("MY_PC_HOSTNAME", UDPPort, #PB_Network_UDP) and then GetClientIP(Con) gonna return IP instead of hostname, if hostname is specified.


heartbone, yeah, i know ExamineIPAddresses(). The thing is, that im getting VirtualBox lan ip from there, which I dont need at all, because if server will send to client VB ip, client will be unable to connect.


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Thu Nov 17, 2016 2:35 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
so your OP mentioned in ipconfig you could see IP addresses you weren't after, but was it also showing you the IP address(es) you were after?

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Fri Nov 18, 2016 4:14 am 
Offline
New User
New User

Joined: Fri Nov 18, 2016 4:11 am
Posts: 1
When IP classes were designed, certain IP addresses were reserved for specific tasks. Broadcast addressing was designed to facilitate message broadcasting for all network devices.

Here is some useful links :

https://www.techopedia.com/definition/2384/broadcast-address
https://supportforums.cisco.com/discussion/12293201/what-broadcast-address
http://www.192168ll.net/


Top
 Profile  
Reply with quote  
 Post subject: Re: LAN Broadcasting and IP
PostPosted: Fri Nov 18, 2016 7:21 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 02, 2003 9:16 am
Posts: 2046
Location: Germany
You basically described your problem as "How do I get my external ip, that is internal inside another LAN".

ewardd wrote:
The thing is, that im getting VirtualBox lan ip from there, which I dont need at all, because if server will send to client VB ip, client will be unable to connect.
I think that highly depends on the way virtualbox is configured. Usually it is using a virtual "router" and NAT. Thats like if you put a router behind a network which has a completely different subnet. The server can't ever know for sure his IP address as seen from the client without sending something in this case. Also the self-connection you use is not useful, since many of the computers, routers and network devices are intelligent enough to not send it outside the subnet. In fact I have my hostname in the /etc/hosts file leading to a local connection only. Also my previous router (I think it was a telekom device) didn't allow connections from the inside over the outside ip back to the inside.

As you send something to the broadcaster, can't the broadcaster find the IP address of the replier itself? I mean every IPv4 package contains source and target IP address.

_________________
bye,
Daniel


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye