Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

get_network_info.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function [ip,mac,hostname]=get_network_info
  2. ip = '0.0.0.0'; mac='0000000000'; hostname='unknown'; % Default values in case ip address cannot be determined
  3. import java.net.*;
  4. try
  5. % This gets the info as seen by the outside world
  6. dbc = db.labdb.getConnection();
  7. userstr=dbc.get('select user()');
  8. userstr=userstr{1};
  9. atx=find(userstr=='@');
  10. hostn=userstr(atx+1:end);
  11. IA=InetAddress.getAllByName(hostn);
  12. catch
  13. % We are not connected to bdata. just use java to get the hostname
  14. % This is basically the same as calling system('hostname');
  15. IA=InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
  16. end
  17. if ~exist('contains','file')
  18. eval('contains=@(x,y)cellfun(@(a)any(strfind(a,y)),{x});')
  19. end
  20. try
  21. keeps=zeros(size(IA));
  22. for ix=1:numel(IA)
  23. if contains(class(IA(ix)),'4') % this is an IPv4 address
  24. ip=char(IA(ix).getHostAddress);
  25. if ip(1)=='0' || isequal(ip,'127.0.0.1') || isequal(ip,'127.0.1.1') % ignore localhost and microsoft tv/video connector
  26. keeps(ix)=0;
  27. else
  28. keeps(ix)=1;
  29. end
  30. end
  31. end
  32. if sum(keeps)==1;
  33. good_IA=find(keeps==1);
  34. elseif sum(keeps)>1
  35. warning('Not sure what my IP address is');
  36. good_IA=find(keeps==1,1,'first');
  37. else
  38. 'Could not find any IP'
  39. [ip,mac,hostname] = deal([]);
  40. return
  41. end
  42. ip=char(IA(good_IA).getHostAddress);
  43. if nargout>1
  44. ni=NetworkInterface.getByInetAddress(IA(good_IA));
  45. if ~isempty(ni)
  46. CA=double(ni.getHardwareAddress);
  47. hostname=char(IA(good_IA).getHostName);
  48. try
  49. for hx=1:6
  50. mac(2*hx-1:2*hx)=dec2hex(mod(CA(hx),2^8),2);
  51. end
  52. catch
  53. mac = '00:00:00:00:00:00';
  54. end
  55. end
  56. end
  57. catch
  58. utils.showerror;
  59. end