zxl
1 天以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.ycl.api.YS.config.network;
 
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_DNS_INFO_S;
 
import javax.swing.*;
import java.util.InputMismatchException;
 
/**
 *
 * @introduction DNS configure
 * @description
 */
public class DNS {
 
    /**
     *
     * @introduction Get DNS information
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getDNSInfo() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
 
        NETDEV_DNS_INFO_S dnsList=new NETDEV_DNS_INFO_S();
        IntByReference dwBytesReturned=new IntByReference();
        dnsList.udwNum=2;
        dnsList.write();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_DNS_CFG, dnsList.getPointer(), dnsList.size(), dwBytesReturned );
        if(bRet != true)
        {
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            dnsList.read();
            for(int i=0;i<dnsList.udwNum;i++) {
                int type=dnsList.astDNSList[i].udwAddressType;
                if(type==0) {
                    NetDemo.jComboBoxIPtypeList.setSelectedIndex(0);
                }else if(type==1) {
                    NetDemo.jComboBoxIPtypeList.setSelectedIndex(1);
                }else if(type==2) {
                    NetDemo.jComboBoxIPtypeList.setSelectedIndex(2);
                }else if(type==3) {
                    NetDemo.jComboBoxIPtypeList.setSelectedIndex(3);
                }
 
                byte[] ip4=dnsList.astDNSList[0].szIPAddress;
                String ip4String1=Common.byteArrayToString(ip4);
                byte[] ip41=dnsList.astDNSList[1].szIPAddress;
                String ip4String2=Common.byteArrayToString(ip41);
 
                NetDemo.textPreferredAddress.setText(ip4String1);
                NetDemo.textAlternate.setText(ip4String2);
            }
        }
    }
 
    /**
     *
     * @introduction Set DNS informaiton
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void setDNSInfo() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
 
        NETDEV_DNS_INFO_S dnsList=new NETDEV_DNS_INFO_S();
        IntByReference dwBytesReturned=new IntByReference();
        dnsList.udwNum=2;
        dnsList.write();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_DNS_CFG, dnsList.getPointer(), dnsList.size(), dwBytesReturned );
        if(bRet != true)
        {
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
 
        dnsList.read();
        dnsList.udwNum=2;
        String mainAddressString=NetDemo.textPreferredAddress.getText().replaceAll("  |","");
        String secondAddressString=NetDemo.textAlternate.getText().replaceAll("  |","");
        if(mainAddressString==null||mainAddressString.equals("")) {
            JOptionPane.showMessageDialog(null, "Please input PreferredAddress");
            return;
        }
        try {
             System.arraycopy(mainAddressString.getBytes(), 0, dnsList.astDNSList[0].szIPAddress, 0, mainAddressString.getBytes().length);
        }catch(NumberFormatException |InputMismatchException e2) {
            JOptionPane.showMessageDialog(null, "PreferredAddress is null or transformation Exception");
            return;
        }
 
 
         if(secondAddressString==null||secondAddressString.equals("")) {
             JOptionPane.showMessageDialog(null, "Please input AlternateAddress");
             return;
         }
         try {
             System.arraycopy(secondAddressString.getBytes(), 0, dnsList.astDNSList[1].szIPAddress, 0, secondAddressString.getBytes().length);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "AlternateAddress is null or transformation Exception");
                return;
            }
         dnsList.write();
         boolean bRet2 = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_DNS_CFG, dnsList.getPointer(), dnsList.size() );
        if(bRet2 != true)
        {
            JOptionPane.showMessageDialog(null, "Get data failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "Set success");
            }
        }
    }
}