Finding a PCs IP address using computer name but using a mac

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Finding a PCs IP address using computer name but using a mac

Post by Da_Elf » Thu Jul 09, 2015 8:34 pm

ok so im using the below code on my PC laptop to get the IP address of another PC on the network so that i can log into its database
This laptop is linked wirelessly (if thats a word) and it can find and contact the computer with the database
I exported the program for mac and tried it on a mac mini with wifi we have here however it didnt work trying to convert the PCs name to IP

Code: Select all

global gConnectionIP
on ContactServer
   put the hostNameToAddress of (the text of fld "DBaseComputer") into testserver
   if testserver is empty then
       answer "Can not find the server computer"
   else
      put testserver &":3306" into gConnectionIP
      answer "Found Server"
   end if
end ContactServer
Last edited by Da_Elf on Thu Jul 09, 2015 9:26 pm, edited 2 times in total.

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

Re: Finding a PCs IP address using computer name but using a

Post by ghettocottage » Thu Jul 09, 2015 10:03 pm

can you assign the database computer a static ip via your router? Might be easier than trying to script all this.

if not, can you ping the computer name from a cmd terminal and get a response?

just: ping testserver

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Finding a PCs IP address using computer name but using a

Post by sturgis » Fri Jul 10, 2015 1:40 am

if I recall correctly, for this to work on a mac you have to change some netbios stuff in the settings. (since windows networks don't use a standard dns type of server thing)

Basically, you'd go into network settings, advanced, go to the WINS tab and set things up so that you're in the right workgroup, and if you have a wins server on the network, you can add its IP there also. It MIGHT be enough to just set up the workgroup and wait. Again, if I recall correctly, machines broadcast their netbios names and hopefully the mac will pick em up. Its been a LONG time since I've done any of this though, so google is your friend.

Another option? Run your own dns and dhcp to assign names and addresses, and have all your machines point to the internal dns.

The final option as mentioned is just hard code your IP's and use those to reference machines.

Just did another search.. On mavericks, it looks like you might be able to use shell

get shell("smbutil lookup computername")
If this works, its probably the easiest answer.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Finding a PCs IP address using computer name but using a

Post by Da_Elf » Sat Jul 11, 2015 4:53 pm

the reason im using hostNameToAddress is because i dont want to have to hardcode the ip address of that system. the correct workgroup is setup on the mac but it still cant find the pc by the pcs computer name

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Finding a PCs IP address using computer name but using a

Post by sturgis » Sat Jul 11, 2015 5:05 pm

Did you try get shell("smbutil lookup computername")
?

Don't know if it will work, but curious to know if it does.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Finding a PCs IP address using computer name but using a

Post by Da_Elf » Sat Jul 11, 2015 10:08 pm

yup. it worked. i had to tell it to check OS and see if it was windows or mac then to tell it which way to do the lookup. the replay i had to do some work to get just the IP from it since it spouts out a bunch of text more than the ip

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Finding a PCs IP address using computer name but using a

Post by SparkOut » Sat Jul 11, 2015 10:20 pm

tracert should work on both windows and Mac OS X, there may be a little variance in response but the first thing that looks like an ip address should be the destination.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Finding a PCs IP address using computer name but using a

Post by sturgis » Sat Jul 11, 2015 10:23 pm

The purpose is to resolve the local ip of a system on the network. In this case using the netbios name of a windows machine, and getting its ip from a mac. Will tracert do this? I'll have to add it to my toolbox if so!

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Finding a PCs IP address using computer name but using a

Post by SparkOut » Sat Jul 11, 2015 10:55 pm

Yes, it should do, I believe. It definitely will on windows. Pretty sure the responses are very similar on OSx.

tracert hostname

and you will see the first line such as
tracing route to hostname (192.168.0.55) blah blah
and then a series of hops indicating the route via each ip of the nodes being traversed. Within a local network there will likely be only one hop, directly to the destination.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Finding a PCs IP address using computer name but using a

Post by Da_Elf » Sun Jul 12, 2015 12:26 am

this is what the tracert method gave me on the PC

Tracing route to CasparMain-PC [192.168.99.101]
over a maximum of 30 hops:

1 1 ms 1 ms 1 ms CasparMain-PC [192.168.99.101]

Trace complete.


on the mac though i get
/bin/sh: line 1: tracert: command not found

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Finding a PCs IP address using computer name but using a

Post by sturgis » Sun Jul 12, 2015 12:27 am

on a mac its spelled out in full: traceroute

So you'll still have to separate the 2 shell calls.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Finding a PCs IP address using computer name but using a

Post by Da_Elf » Sun Jul 12, 2015 12:55 am

ok im not sure how to use it this time i get :
traceroute:unknown host CASPARMAIN-PC

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Finding a PCs IP address using computer name but using a

Post by sturgis » Sun Jul 12, 2015 12:59 am

Ah k. Thats the answer then. If you don't have your mac set up to do netbios name resolution, it won't work. Looks like you'll still want to stick with the other method unless you can figure out how to get resolution working. (Its been too long, i'm not sure how) the smbutil method should work fine though.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Finding a PCs IP address using computer name but using a

Post by Da_Elf » Sun Jul 12, 2015 1:22 am

the smbutil one is fine for me. as long as it works is all i care about

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Finding a PCs IP address using computer name but using a

Post by SparkOut » Sun Jul 12, 2015 8:29 am

Yes, if tracert and traceroute mean you need to use different calls anyway, just use what you know will work.

Post Reply