Get IP address over a Edit box
Mostrar comentarios más antiguos
Hi all,
I need to get a IP address kind of values from the edit box.i.e, I have to get like 10 values from one edit box. I've planned to give an edit box like image shown below,

How to do this in edit box . I remember seeing this in some undocumented matlab using combo boxes but i can't recall it.
Respuesta aceptada
Más respuestas (2)
You can use a standard edit box and perform the checks in the callback, e.g.:
function EditCallback(hObject, EventData, handles)
Str = get(hObject, 'String');
[Num, N] = sscanf(Str, '%d.%d.%d.%d');
if N == 4 && && all(Num > 0) && all(Num < 256)
Str = sprintf('%03d.%03d.%03d.%03d', Num); % Or: '%d.%d.%d.%d' if you like it
set(hObject, 'String', Str, 'Color', [0,0,0]);
handles.IP = Str;
guidata(hObject, handles);
else % Warn the user, that this is no valid IP:
set(hObject, 'Color', [1,0,0]);
end
end
Image Analyst
el 19 de Sept. de 2022
Editada: Image Analyst
el 19 de Sept. de 2022
A related answer, if you want to get the IP address of your own computer, you can do this (if you're using a Windows system):
[status, commandOutput] = system('ipconfig')
str = 'IPv4 Address. . . . . . . . . . . : ';
% Extract ip addresses. There will be one for each network adapter, e.g. wired, wireless, etc.
index = strfind(commandOutput, str);
startingIndex = index + length(str)
for k = 1 : length(startingIndex)
s = commandOutput(startingIndex(k):startingIndex(k)+15);
% Get rid of any trailing non-numeric characters
while isnan(str2double(s(end))) && length(s) > 1
s = s(1 : end-1);
end
ipAddress{k} = s;
fprintf('IP Address #%d = %s\n', k, s);
end
Categorías
Más información sobre Language Support en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
