就是点击一下按钮,然后可以搜索到附近的以太网的ip,显示在我的editview上面,应该如何编写程序,或者提供思路也行,感激不尽!
建议看下网络方面的,都很简单的
这个不难的吧,就是网络
你是在wife下还是怎么的?
java:
public class MainActivity {
public static String loadFileAsString(String filePath) throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(filePath));
char[] buf = new char[1024]; int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
return fileData.toString();
}/** Get the STB MacAddress*/
public static String getMacAddress(){
try {
return loadFileAsString("/sys/class/net/eth0/address") .toUpperCase().substring(0, 17);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
System.out.println("WifiPreference IpAddress"+ex.toString());
}
return null;
}
}
c:
void SearchSensor(WM_MESSAGE * pMsg)
{
WM_HWIN hItem;
int remoteip;
int row = 0;
char lastremoteip[24];
for(remoteip = 0; remoteip < 256; remoteip ++)
{
connect_re(sendpcb, remoteip, SENSOR_PORT);
cpc_send_data(sendpcb, ptSearchSensor);
GUI_Delay(10);
if(setflag.SearchSensor == 1)
{
setflag.SearchSensor = 0;
hItem = WM_GetDialogItem(pMsg->hWin, PARA_LISTVIEW_SENSOR);
sprintf(lastremoteip, "%d.%d.%d.%d", lwipdev.remoteip[0],lwipdev.remoteip[1],lwipdev.remoteip[2],lwipdev.remoteip[3]);
LISTVIEW_SetItemText(hItem, 0, row , lastremoteip);
LISTVIEW_SetItemText(hItem, 1, row , receive_data->Contact.Sensor.SensorName); //列 行
row ++;
}
}
}