1 /*###########################################################################
3 # Copyright (C) 2007 - 2009 by
4 # nixkoenner <nixkoenner@newnigma2.to>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 ###########################################################################*/
28 #include "showmount.h"
30 PyObject *_netInfo(PyObject *self, PyObject *args)
32 const unsigned int max_hosts = 256;
38 if(!PyArg_ParseTuple(args, "s", &s)) {
39 PyErr_SetString(PyExc_TypeError, "netInfo(ip/24)");
43 result = PyList_New(0);
47 nInfo = PyMem_New(netinfo, max_hosts);
51 Py_BEGIN_ALLOW_THREADS
52 n = netInfo(s, nInfo, max_hosts);
55 for (i = 0; i < n; i++) {
56 PyObject *plist = PyList_New(0);
59 PyList_Append(plist, PyString_FromString("host"));
60 PyList_Append(plist, PyString_FromString(nInfo[i].name));
61 PyList_Append(plist, PyString_FromString(nInfo[i].ip));
62 PyList_Append(plist, PyString_FromString(nInfo[i].mac));
63 PyList_Append(plist, PyString_FromString(nInfo[i].domain));
64 PyList_Append(plist, PyString_FromString(nInfo[i].service));
65 PyList_Append(result, plist);
72 PyObject *_nfsShare(PyObject *self, PyObject *args)
77 PyObject *plist, *result, *share, *ip, *nfsShare, *rech, *rechip, *leer;
81 if(!PyArg_ParseTuple(args, "ss", &s, &r)) {
82 PyErr_SetString(PyExc_TypeError, "nfsShare(ip,rechnername)");
86 if(!(plist= PyList_New(0))) return NULL;
87 if(!(result= PyList_New(0))) return NULL;
89 nfsInfo = newNfsInfo();
90 Py_BEGIN_ALLOW_THREADS
91 err = showNfsShare(s, nfsInfo);
97 if(nfsInfo[i].ip[0] == '\0') {
102 ip = Py_BuildValue("s", nfsInfo[i].ip);
103 share = Py_BuildValue("s", nfsInfo[i].share);
104 nfsShare = Py_BuildValue("s", "nfsShare");
105 rech = Py_BuildValue("s",r);
106 rechip = Py_BuildValue("s",s);
107 leer = Py_BuildValue("s","");
108 PyList_Append(plist, nfsShare);
109 PyList_Append(plist, rech);
110 PyList_Append(plist, rechip);
111 PyList_Append(plist, ip);
112 PyList_Append(plist, share);
113 PyList_Append(plist, leer);
114 PyList_Append(result, plist);
115 if(!(plist= PyList_New(0))) return NULL;
121 share = Py_BuildValue("s", nfsInfo[0].share);
122 PyList_Append(plist, share);
123 PyList_Append(result, plist);
124 if(!(plist= PyList_New(0))) return NULL;
126 freeNfsInfo(nfsInfo);
130 PyObject *_smbShare(PyObject *self, PyObject *args)
138 PyObject *plist, *name, *typ, *comment, *result, *smbShare, *rech, *rechip;
141 if(!PyArg_ParseTuple(args, "ssss", &s,&r,&u,&p)) {
142 PyErr_SetString(PyExc_TypeError, "getInfo(ip, rechnername, username, passwort)");
145 if(!(plist= PyList_New(0))) return NULL;
146 if(!(result= PyList_New(0))) return NULL;
148 Py_BEGIN_ALLOW_THREADS
149 sInfo = newShareInfo();
150 smbInfo(s,r,u,p,sInfo);
153 for (i=0; i<128; i++)
155 if(sInfo[i].sharename[0] == '\0') {
160 name = Py_BuildValue("s", sInfo[i].sharename);
161 typ = Py_BuildValue("s", sInfo[i].typ);
162 comment = Py_BuildValue("s", sInfo[i].comment);
163 smbShare = Py_BuildValue("s", "smbShare");
164 rech = Py_BuildValue("s",r);
165 rechip = Py_BuildValue("s",s);
166 PyList_Append(plist, smbShare);
167 PyList_Append(plist, rech);
168 PyList_Append(plist, rechip);
169 PyList_Append(plist, name);
170 PyList_Append(plist, typ);
171 PyList_Append(plist, comment);
172 PyList_Append(result, plist);
173 if(!(plist= PyList_New(0))) return NULL;
176 freeShareInfo(sInfo);
178 //return Py_BuildValue("s",s);
181 static PyMethodDef netscanmethods[] = {
182 {"netInfo", _netInfo, METH_VARARGS},
183 {"smbShare", _smbShare, METH_VARARGS},
184 {"nfsShare", _nfsShare, METH_VARARGS},
188 void initnetscan(void)
190 Py_InitModule("netscan", netscanmethods);