PDA

View Full Version : Connecting to lan web server


SearchFor
2004-12-28, 14:47
hi all

i'm trying to make a script to switch off my media server. so far it works quite well except for the fact the lan ips are hardcoded into the script but i would like to use server names rather than ips (they are dhcp assigned on my network so somtimes change)

why can't i use the (windows) server name as is possible on win32 python?

heres the script as it is now, works on xbmc and win32 python
import urllib
temp = urllib.urlopen('http://usernm:password@192.168.0.7:9000/action.htm?action=hibernate').read()


but this is how i would like it be, this only works on win32 python
import urllib
temp = urllib.urlopen('http://usernm:password@saturn:9000/action.htm?action=hibernate').read()


in my debugging i have tried importing httplib and using httplib.httpconnection(url) with the same effect

also tried importing socket and using socket.getfqdn(servername)/gethostbyname(servername) with some string concat to create the url but it never worked either


i've never scripted python before so any suggestions would be welcomed

tia

jaga
2004-12-28, 17:07
afaik, you can't. use a dns name or ip.

SearchFor
2004-12-28, 22:44
afaik, you can't. use a dns name or ip.
bbzzzzzth

we have a winner...me! ;)

you need pysmb samba/netbios client-python libs (http://miketeo.net/projects/pysmb/index.html),

thelibs also allow python file upload + download if anyone's interested :) ... read the discliamer, experimental only need to be tested with xp, winme, opensource, very relaxed licence, designed for python versions<=2.3

import urllib, smb,nmb

ip = nmb.netbios().gethostbyname('saturn')[0].get_ip()

temp = urllib.urlopen('http://usernm:password@'+ip+':9000/action.htm?action=hibernate').read()


i tested this script on xp, did not work, poss due to conflict with xp's built in netbios client or incompatability, worked fine on xbox

cheers