session.hostname = os.system("dig +short +time=1" + " " + 
request.vars.hostname)

does not do what you think. os.system does not return the output of the 
"dig" call. It only returns success (0) or failure (-1).

You could use os.system("dig +short +time=1" + " " + 
request.vars.hostname+" > myfile") to send the output to a file and then 
read it but it is not thread safe.

If you want to use dig, than you should use os.Popen and read the output 
from a pipe.

Or try 
this: 
http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib

On Sunday, 9 August 2015 08:36:05 UTC-5, Heinrich Piard wrote:
>
> Any idea why my view does not show the result of "ipaddress"?
>
> On Fri, Aug 7, 2015 at 7:38 PM, Heinrich Piard <[email protected]> 
> wrote:
>
>> Hi,
>>
>> I this default.py
>>
>> import os
>> import sys
>>
>> def nslookup():
>>     form = SQLFORM.factory(Field('hostname',
>>                                  label='Please enter a valid HOSTNAME to 
>> resolve:',
>>                                  requires=IS_NOT_EMPTY()))
>>     if form.process().accepted:
>>         response.flash = "Hostname accepted"
>>         session.hostname = os.system("dig +short +time=1" + " " + 
>> request.vars.hostname)
>>     else:
>>         response.flash = 'Please fill the form with a valid hostname'
>>     ipaddress = session.hostname
>>     return dict(form=form, ipaddress=ipaddress)
>>
>> and respective nslookup.html
>>
>> {{extend 'layout.html'}}
>> <h1>Domain Name Lookup Tool</h1>
>>
>> {{=form}}
>>
>> <h2>
>>     Entered HOSTNAME has IP Address:
>> </h2>
>> {{=BEAUTIFY(ipaddress)}}
>>
>>
>>
>> However, the resolved IP does not work though I see the nslookup when 
>> doing a tcpdump.
>>
>> Any help would be appreciated.
>>
>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to